0
PowershellをAzureで使用する際に問題があります。私が持っているのはPowershell Azureコマンドを実行している小さなC#コンソールアプリケーションです。Powershell Azure CmdletInvocationException
これは私のコードです:
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."