工具:VS 2010,.Net 3.5(特别提示.net 4不支持)
环境:PS V2,Windows 7
using System;
using System.Collections.Generic;
using System.Text;
using System.Management.Automation;
using System.Collections;
using System.Management;
using System.Collections.ObjectModel;
namespace Snapin
{
[Cmdlet(VerbsCommon.Get, "Hi")]
public class Snapin : PSCmdlet
{
protected override void ProcessRecord()
{
try
{
string str = "Hello Snapin";
WriteObject(str, false);
}
catch (Exception)
{
}
}
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Text;
using System.Management.Automation;
namespace Snapin
{
[RunInstaller(true)]
public class SnapinPSSnapIn : PSSnapIn
{
public override string Name
{
get { return "SnapinHello"; }
}
public override string Vendor
{
get { return "Fanr"; }
}
public override string VendorResource
{
get { return "SnapinHello,Fanr"; }
}
public override string Description
{
get { return "Registers the CmdLets and Providers in this assembly"; }
}
public override string DescriptionResource
{
get { return "Snapin,Registers the CmdLets and Providers in this assembly"; }
}
}
}