[英]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.