[英]Create Remote Powershell Session and load modules in Runspace using C#
[英]How to load powershell module using C# Runspace
嘗試在C#中使用Azure cmdlet,除特定的“ Get-RoleInstanceCount”即Azure之外,其他所有功能均正常運行。 Azure cmdlet promt啟動時將運行以下命令:
C:\Windows\SysWOW64\WindowsPowerShell\v1.0\powershell.exe -NoExit -Command "cd c:\; Import-Module 'C:\Users\me\Documents\WindowsPowerShell\Modules\WAPPSCmdlets\WAPPSCmdlets.dll'"
我嘗試了以下方法:
InitialSessionState initialSessionState = InitialSessionState.CreateDefault();
initialSessionState.ImportPSModule(new string[] {"C:\\Users\\me\\Documents\\WindowsPowerShell\\Modules\\WAPPSCmdlets\\WAPPSCmdlets.dll"});
Runspace runspace = RunspaceFactory.CreateRunspace(initialSessionState);
就像他們在這里一樣:
http://msdn.microsoft.com/zh-CN/library/windows/desktop/ee706596(v=vs.85).aspx
.dll模塊位於Debug文件夾中的上述路徑中。 但是,當我嘗試“打開()”運行空間時,出現以下異常:
無法加載文件或程序集“ WAPPSCmdlet”或其依賴項之一。 找到的程序集的清單定義與程序集引用不匹配。 (來自HRESULT的異常:0x80131040)
我該怎么做才能加載使我能夠運行Azure命令的模塊?
由於無法成功加載cmdlet,因此我不確定“ Get-RoleInstanceCount”以外的命令如何工作。 您可以再次檢查以確保它們工作正常嗎? 如果不是,請嘗試重新安裝該cmdlet。
此外,您可以直接使用RESTful Windows Azure管理API,而無需PowerShell。 PowerShell可以通過將HTTP請求封裝到cmdlet中來提供簡化的編程模型。 但是,如果這不起作用,您始終可以選擇直接使用REST API。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.