任何人都可以帮我将C#.NET程序转换为PowerShell cmdlet吗?我对这个领域很新.请帮我走出这个检查站!
问候,
阿伦
添加对System.Management.Automation的引用,创建一个继承自Cmdlet的类并重写ProcessRecord方法:
[Cmdlet(VerbsCommon.Get, "Double")] public class GetDouble : Cmdlet { [Parameter] public int SomeInput { get; set; } protected override void ProcessRecord() { WriteObject(SomeInput * 2); } }
添加安装程序:
[RunInstaller(true)] public class MySnapin : PSSnapIn { public override string Name { get { return "MyCommandlets"; } } public override string Vendor { get { return "MyCompany"; } } public override string Description { get { return "Does unnecessary aritmetic."; } } }
安装命令行开关程序集:
Installutil /i myassembly.dll
并添加:
Add-PsSnapin MyCommandlets