简体   繁体   English

System.Management.Automation错误访问被拒绝

[英]System.Management.Automation error access denied

System.Management.Automation class I use the c # PowerShell exchange programs that access the server, increase the tasks of e-mail accounts, a program error access denied; 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>

Well.. an access denied error is pretty straightforward. 嗯..访问被拒绝错误非常简单。 I modified your code a little bit: 我对您的代码做了一些修改:

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

If this does not work, you can try establishing a remote session through PowerShell to see if you actually have access to the server. 如果这不起作用,则可以尝试通过PowerShell建立远程会话,以查看您是否真正有权访问服务器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 MVC System.Management.Automation Powershell执行中的访问被拒绝错误 - Access Denied error in MVC System.Management.Automation powershell execution 加载System.Management.Automation程序集时出错 - Error loading System.Management.Automation assembly System.Management.Automation中没有PowerShell? - No PowerShell in System.Management.Automation? c# Core System.Management.Automation远程连接错误 - c# Core System.Management.Automation remote connection error 2.0版的System.Management.Automation? - 2.0 version of System.Management.Automation? 如何使用系统管理自动化 - How to use System.Management.Automation 使用 System.Management.Automation 时,如何访问 .NET Core 中的 CimCmdlets? - How do I get access to CimCmdlets in .NET Core when using System.Management.Automation? 运行 Start-DSCConfiguration 时出错:无法加载文件或程序集“System.Management.Automation”,版本 = 7.1.0.0 - Error when running Start-DSCConfiguration: Could not load file or assembly 'System.Management.Automation', Version=7.1.0.0 DNX的ASP.NET 5 MVC 6 System.Management.Automation问题 - ASP.NET 5 MVC 6 System.Management.Automation issue with DNX 从 System.Management.Automation 调用脚本时未设置 $PSScriptRoot - $PSScriptRoot not set when invoking script from System.Management.Automation
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM