13

I've got a really simple powershell script (see below). I've got installutil aliased using the following in my profile:

set-alias installutil $env:windir\Microsoft.NET\Framework\v2.0.50727\installutil

In powershell I simply:

installutil assemplylocation.dll

This returns successfully. (Install/Commit both complete successfully). Yet when I check the registry, or in powershell using get-pssnapin -registered it doesn't show my assembly. I did this the other day and it worked fine, but I don't seem to be able to duplicate it ... please advise.

using System;
using System.Management.Automation;
using System.ComponentModel;

namespace PSBook_2_1
{
    [RunInstaller(true)]
    public class PSBookChapter2MySnapIn : PSSnapIn
    {
        public PSBookChapter2MySnapIn()
            : base()
        { }

    // Name for the PowerShell snap-in.
    public override string Name
    {
        get
        {
            return "Wiley.PSProfessional.Chapter2";
        }
    }

    // Vendor information for the PowerShell snap-in.
    public override string Vendor
    {
        get
        {
            return "Wiley";
        }
    }

    // Description of the PowerShell snap-in
    public override string Description
    {
        get
        {
            return "This is a sample PowerShell snap-in";
        }
    }
}

// Code to implement cmdlet Write-Hi
[Cmdlet(VerbsCommunications.Write, "Hi")]
public class SayHi : Cmdlet
{
    protected override void ProcessRecord()
    {
        WriteObject("Hi, World!");
    }
}

// Code to implement cmdlet Write-Hello
[Cmdlet(VerbsCommunications.Write, "Hello")]
public class SayHello : Cmdlet
{
    protected override void ProcessRecord()
    {
        WriteObject("Hello, World!");
    }
}

}

downatone
  • 1,936
  • 2
  • 23
  • 30

7 Answers7

14

downatone's answer put me on the right track but my problem was the opposite way round. My project is set to any CPU and I am on Win7 x64 so the powershell being launched from my code and then installing the dll with the snapin was 64 bit. However the install command I used was pointing to the 32 bit .net runtime i.e.

C:\Windows\Microsoft.net\Framework\V4.0.30319\installutil myDLL.dll

when it should have been

C:\Windows\Microsoft.net\Framework64\V4.0.30319\installutil myDLL.dll

Note the 64 in the Framework path.

Alan Macdonald
  • 1,872
  • 20
  • 36
11

Turns out the issue was that I had a 32-bit cmdlet - but was only checking the 64-bit version of powershell ...

downatone
  • 1,936
  • 2
  • 23
  • 30
  • 1
    I just experienced this problem as well. The list of snapins is maintained in HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PowerShell\1\PowerShellSnapIns but the registry gets Virtualised by the OS if you are accessing it with a 32 bit process. You can see the details of the registry calls using Sysinternals Process Monitor. – Martin Hollingsworth Jun 04 '10 at 01:28
  • 1
    Yeah so the command should have been: set-alias installutil $env:windir\Microsoft.NET\Framework64\v2.0.50727\installutil – Mandrake Aug 16 '12 at 20:16
1

run as administrator to run ps

1

Did you run installutil as an elevated user? It writes information to protected portions of the registry. If you do this as a non-admin on Vista it can produce strange results.

JaredPar
  • 733,204
  • 149
  • 1,241
  • 1,454
1

The key point for me here was remembering that Visual Studio 2010 is still a 32 bit application meaning that when I used the Command Prompt it defaulted to the 32-bit variant of InstallUtil. Its not immediately obvious in this case that the registry keys are therefore written to the Wow64-bit node instead of the 64-bit registry proper.

Ben Rose
  • 11
  • 1
0

I had to use the x86 (32bit) version of PowerShell to add the Snapin. As I found it not as straight forward as it's supposed to be here's a helpful link how to open PowerShell 32bit:

http://technet.microsoft.com/en-us/library/hh847733.aspx

Kevin Goedecke
  • 1,553
  • 2
  • 14
  • 26
-1

Experienced the same issue - I was trying to use command

C:\Windows\Microsoft.net\Framework\V4.0.30319\installutil myDLL.dll 

instead of

C:\Windows\Microsoft.net\Framework64\V4.0.30319\installutil myDLL.dll 

while having 64 bit cmdlet (project config. Any CPU) on OS win2k8 x64..

andrewsi
  • 10,807
  • 132
  • 35
  • 51