![](/img/trans.png)
[英]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.