0

我想以与使用 Powershell 命令登录相同的方式连接到 Azure。由于我还没有找到任何使用 .NET 执行此操作的 API,我认为使用 .NET 执行 PS 脚本是一个好主意。

我已经在笔记本电脑上安装了 Powershell for azure

Install-Module -Name Az -AllowClobber

我还尝试在我的 PC 的 Windows Powershell 中使用“Connect-AzAccount”命令,它工作正常。

因此,我在 Visual Studio 中尝试了以下操作:

using System.Management.Automation;

namespace AzureTestVM
{
    class Program
    {

        static void Main(string[] args)
        {
            PowerShell ps = PowerShell.Create().AddCommand("Connect-AzAccount");
            ps.Invoke();
        }
    }
}

问题是我收到以下错误:

Unhandled Exception: System.Management.Automation.CmdletInvocationException: Method
'get_SerializationSettings' on type' 
Microsoft.Azure.Management.Internal.Resources.ResourceManagementClient 'of assembly' 
Microsoft.Azure.PowerShell.Clients.ResourceManager, Version = 1.0. 0.0, Culture = neutral,    
PublicKeyToken = 31bf3856ad364e35 'does not have an implementation. --->
 System.TypeLoadException: Method 'get_SerializationSettings' on type' 
Microsoft.Azure.Management.Internal.Resources.ResourceManagementClient 'of assembly' 
Microsoft.Azure.PowerShell.Clients.ResourceManager, Version = 1.0.0.0, Culture = neutral, 
PublicKeyToken = 31bf3856ad364e35 'does not have an implementation.
4

0 回答 0