views:

925

answers:

3

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!");
    }
}

}

A: 

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
+2  A: 

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

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
A: 

run as administrator to run ps