Azure powershell命令从c#应用程序失败

时间:2014-07-02 12:16:22

标签: c# powershell azure-powershell

我正在尝试从我的c#app调用Azure Powershell命令(使用windows auth运行) Azure PowerShell sdk安装在Windows 2012 R2的“User1”框中,后者也是网络和框的管理员。 使用的代码:

string psFile= @"C:\AVC\Vmstatus.ps1 -VmName testvm";
Runspace runspace = RunspaceFactory.CreateRunspace();
            runspace.Open();
            Pipeline pipeline = runspace.CreatePipeline();
            pipeline.Commands.AddScript(psFile);
            pipeline.InvokeAsync();
            WaitHandle[] handles = new WaitHandle[2];
            handles[0] = pipeline.Output.WaitHandle;
            handles[1] = pipeline.Error.WaitHandle;

            while (pipeline.PipelineStateInfo.State == PipelineState.Running)
            {
                switch (WaitHandle.WaitAny(handles))
                {
                    case 0: a = pipeline.Output.Read();
                        vm.ip = ((dynamic)a).IpAddress;
                        vm.vmStatus = ((dynamic)a).PowerState;
                        vm.vmName = ((dynamic)a).name;


                        break;
                    case 1: object b = pipeline.Error.Read();
                        throw new CryptographicException(b.ToString());
                }
            }

场景的

  1. 代码以VS1登录时以User1 - Works
  2. 身份登录
  3. 以用户2身份登录时从Vs 2013运行代码 - 正常工作
  4. 代码从iis运行为User1 -Works
  5. 最糟糕的=>代码从IIS作为user2运行当USer1登录到框-Works
  6. 代码从IIS作为用户2运行 - 无法运行
  7. 从用户2-工作的普通PowerShell运行
  8. 从Azure powershell cmd作为用户2-works
  9. 运行

    我正在使用VS来调试IIS应用程序,并且收到的异常是

    System.Security.Cryptography.CryptographicException: The system cannot find the file specified.
    
    FullyQualifiedErrorId = "Microsoft.WindowsAzure.Commands.Profile.ImportAzurePublishSettingsCommand"
    

    深入研究问题: 1)为user1和user 2安装证书

0 个答案:

没有答案