簡體   English   中英

Powershell Azure CmdletInvocationException

[英]Powershell Azure CmdletInvocationException

我在使用Powershell for Azure時遇到問題。 我所擁有的是一個小的C#控制台應用程序,可以在其中運行Powershell Azure命令。

這是我的代碼:

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();
        ...
        ...
        ...

發生以下異常: rs.Open()

異常如下:

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."

解決方案:我重新安裝了與Azure有關的所有內容,然后一切正常

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM