Where to find the System.Management.Automation assembly

Recent deployments of powershell don’t come with this assembly, which you need to write cmdlets in C#.

You need to install the powershell 2.0 sdk and look for:

$(ProgramFiles)Reference AssembliesMicrosoftWindowsPowerShellv1.0System.Management.Automation.dll

Here is a simple cmdlet:

using System.Management.Automation;

namespace SimpleGreeting
{
[Cmdlet(VerbsCommunications.Send, “Greeting”)]
public class SendGreetingCommand : Cmdlet
{
[Parameter(Mandatory=true)]
public string Name { get; set; }

protected override void ProcessRecord()
{
WriteObject(“Hello” + Name + “!”);
}
}

}

And here is the installer required:

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

namespace SimpleGreeting
{
[RunInstaller(true)]
public class RegisterSimpleGreeting : PSSnapIn
{
public override string Description
{
get { return “This is a demo snapin”; }
}

public override string Name
{
get { return “SendGreetingSnapin”; }
}

public override string Vendor
{
get { return “C.J Eyre Harlequin Design”; }
}
}
}

You need to use installutil to register the snapin.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s