简体   繁体   中英

How to load powershell module using C# Runspace

Trying to use Azure cmdlets in C# and everything is working except the specific "Get-RoleInstanceCount" which is Azure. The Azure cmdlet promt run the following when it starts:

C:\Windows\SysWOW64\WindowsPowerShell\v1.0\powershell.exe -NoExit -Command "cd c:\; Import-Module 'C:\Users\me\Documents\WindowsPowerShell\Modules\WAPPSCmdlets\WAPPSCmdlets.dll'"

I tried the following:

InitialSessionState initialSessionState = InitialSessionState.CreateDefault();
initialSessionState.ImportPSModule(new string[] {"C:\\Users\\me\\Documents\\WindowsPowerShell\\Modules\\WAPPSCmdlets\\WAPPSCmdlets.dll"});
Runspace runspace = RunspaceFactory.CreateRunspace(initialSessionState);

And also like they do it here:

http://msdn.microsoft.com/en-us/library/windows/desktop/ee706596(v=vs.85).aspx

The .dll module is located in the Debug folder and at the above path. But when I try to "open()" the runspace I get the following exception:

Could not load file or assembly 'WAPPSCmdlets' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

What can I do so that it loads the module which enables me to run Azure commands?

Since the cmdlet cannot be loaded successfully, I am not sure how commands other than "Get-RoleInstanceCount" can work. Can you check again to make sure they're working fine? If not, then try to reinstall the cmdlet.

In addition, you can use the RESTful Windows Azure Management API directly without PowerShell. PowerShell may provide a simplified programming model by encapsulating HTTP requests into cmdlets. But if that doesn't work, you always have the option to use the REST API directly.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM