2016-06-28 2 views
0

Powershell을 사용하여 Azure에 문제가 있습니다. 내가 가지고있는 것은 PowerShell Azure 명령을 실행중인 작은 C# 콘솔 응용 프로그램입니다. rs.Open()Powershell Azure CmdletInvocationException

예외는 다음과 같다 :

An unhandled exception of type 'System.Management.Automation.CmdletInvocationException' occurred in System.Management.Automation.dll 

Additional information: Exception calling ".ctor" with "0" argument(s): "The type initializer for 'Microsoft.Azure.Commands.ResourceManager.Common.AzureRMCmdlet' threw an exception." 

답변

0

솔루션 :

public class PowerShellService : IDisposable 
{ 
    private PowerShell _shellInstance; 
    private PSDataCollection<PSObject> _outputCollection; 
    private Runspace rs; 

    public event EventHandler<DataEventArgs> Data; 
    public event EventHandler<ErrorRecordEventArgs> Error; 

    public PowerShellService() 
    { 
     InitializeShellInstance(); 
    } 

    private void InitializeShellInstance() 
    { 
     InitialSessionState iss = InitialSessionState.CreateDefault(); 
     string[] modules = new string[] { "Full path to Azure.psd1", "Full path to AzureRM.psd1" }; 
     iss.ImportPSModule(modules); 

     _shellInstance = PowerShell.Create(); 
     string initializationScript = "Set-ExecutionPolicy -Scope Process -ExecutionPolicy RemoteSigned"; 
     _shellInstance.AddScript(initializationScript); 
     _shellInstance.Invoke(); 

     rs = RunspaceFactory.CreateRunspace(iss); 
     rs.Open(); 
     ... 
     ... 
     ... 

예외가 온라인 발생

내 코드 나는 다음을 푸른 관련된 모든 것을 다시 설치하고 근무한

관련 문제