【问题标题】:System.Management.Automation error access deniedSystem.Management.Automation 错误访问被拒绝
【发布时间】:2017-06-25 17:51:06
【问题描述】:

System.Management.Automation 类我用c# PowerShell 交换程序访问服务器,增加任务邮件帐户,程序错误访问被拒绝;

<pre><code>
 PSCredential credentials = new PSCredential(UserName, ssRunasPassword);
              //ExchangeUri=ExUri
                WSManConnectionInfo connectionInfo = new WSManConnectionInfo(ExchangeUri, "http://schemas.microsoft.com/powershell/Microsoft.Exchange", credentials);
                connectionInfo.AuthenticationMechanism = AuthenticationMechanism.Basic;

                Runspace runspace = RunspaceFactory.CreateRunspace(connectionInfo);
                runspace.Open();
</code></pre>

【问题讨论】:

    标签: c# powershell exchange-server


    【解决方案1】:

    嗯.. 拒绝访问错误非常简单。我稍微修改了你的代码:

            string username = @"domain\username";
            string password = "pass";
            SecureString securePassword = new SecureString();
            foreach (char c in password)
            {
                securePassword.AppendChar(c);
            }
            securePassword.MakeReadOnly();
    
            PSCredential credentials = new PSCredential(username, securePassword);
            //ExchangeUri=ExUri
            WSManConnectionInfo connectionInfo = new WSManConnectionInfo(new Uri(ExUri), "http://schemas.microsoft.com/powershell/Microsoft.Exchange", credentials);
            connectionInfo.AuthenticationMechanism = AuthenticationMechanism.Basic;
    
            Runspace runspace = RunspaceFactory.CreateRunspace(connectionInfo);
            runspace.Open();
    

    如果这不起作用,您可以尝试通过PowerShell 建立远程会话,看看您是否真的可以访问服务器。

    【讨论】:

    • 嗨。谢谢你的回答,不过好像没有特殊的代码改动,只是添加了我没贴的代码的用户名和密码,拒绝访问提示是我建服务器的问题
    猜你喜欢
    • 2017-04-06
    • 1970-01-01
    • 2010-10-24
    • 2012-12-21
    • 2010-12-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-08-29
    相关资源
    最近更新 更多