回答
的參考添加到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
僅供參考:System.Management.Automation可以在從Windows SDK安裝參考程序集後引用。 – 2008-12-05 15:55:51
偉大的提示。也是很好的答案,這正是我所期待的。 – 2010-08-05 23:01:00
首先,你應該轉換.cs文件到使用PowerShell模板的DLL。然後通過使用pssnapin
和getproc
您可以將其轉換爲DLL。
有一個反射器來做到這一點的附加組件。 下面是用例的好文章:http://msmvps.com/blogs/paulomorgado/archive/2009/09/18/powershell-for-the-net-developer.aspx *
.NET反射器具有an array of add-ons on CodePlex,而這些 之一是the PowerShell add-on,使您可以拆卸代碼直接 到PowerShell中。
在這個例子中,我從 的SPUtility圖書館開放的方法ChangeAccountPassword在SharePoint:
我現在可以改變從C#的目標,以PowerShell的。
當你需要的輔助方法轉換從C#到PowerShell的,或者如果 你是新來的PowerShell語法,這個工具是非常有幫助!
[*]該鏈接截至2015年12月12日已死亡。
- 1. 將.cs轉換爲.dll
- 2. 將cs轉換爲vb
- 3. 轉換cs文件編碼
- 4. Powershell:將電子郵件字符串轉換爲Send-MailMessage cmdlet的有效格式
- 5. 如何使用PowerShell將多個xls文件轉換爲csv?
- 6. Powershell將正文轉換爲HTML正文
- 7. Powershell如何將System.Collections.Generic.Dictionary轉換爲PSCustomObject?
- 8. Powershell:如何將ADUser轉換爲IdentityReference?
- 9. 如何將.cmd轉換爲PowerShell腳本?
- 10. 將LinQ查詢生成器轉換爲C#中的.cs文件
- 11. 如何將json轉換爲cs中datatable.xmlread()類可讀取的xml文件#
- 12. 如何將C#代碼轉換爲PowerShell腳本?
- 13. PowerShell Cmdlet
- 14. 將Wget調用轉換爲PowerShell
- 15. 將Unix1Liner轉換爲PowerShell
- 16. 訪問c#上的bin文件夾的文件(將.dll轉換爲.cs)
- 17. PowerShell的 - 日誌文件轉換爲CSV
- 18. 如何將AudioBuffer轉換爲mp3文件?
- 19. 如何將3dmax文件轉換爲flash?
- 20. 如何將hashMap轉換爲Json文件
- 21. 如何將.ai文件轉換爲PNG
- 22. 如何將pem轉換爲pfx文件?
- 23. 如何將HSSFWorkbook轉換爲CSV文件..?
- 24. 如何將WAV文件轉換爲M4A?
- 25. 如何將bytearray轉換爲zip文件
- 26. 如何將.rst文件轉換爲.md?
- 27. 如何將(.JAR)文件轉換爲UML?
- 28. 如何將m文件轉換爲dll?
- 29. 如何將此文件轉換爲yml?
- 30. 如何將JPanel轉換爲文件?
[將C#代碼轉換爲PowerShell腳本的方法?]的可能的副本(http://stackoverflow.com/questions/2143460/methods-to-convert-c-sharp-code-to-a-powershell-script ) – 2016-04-11 22:36:23