我写了一个远程访问从asp.net应用程序的远程访问代码,以启用远程邮件使用vb.net和Exchange 2016命令运行成功从我的Visual Studio调试,但是当我把iis web服务器它给了我PowerShell远程调用。访问被拒绝从IIS
访问被拒绝
我添加的用户到服务器管理员/本地管理干部甚至orgnization管理员ASLO我更改应用程序池是一个服务器管理员用户 ,仍然得到同样的错误在网络服务器
这是代码
string back = "";
try
{
string ServerUri = "http://{server}/PowerShell/";
//use one of CAS servers
string SchemaUri = "http://schemas.microsoft.com/powershell/Microsoft.Exchange";
string userName = AccountOperatorLogon;
//user must be member of "Recipient Management" group to create Mailboxes
System.Security.SecureString password = new System.Security.SecureString();
foreach (char x in AccountOperatorPassword)
{
password.AppendChar(x);
}
string onmicrosoftemail = Email.ToLower().Replace("mail.com", "mail.onmicrosoft.com");
PSCredential PSCredential = new PSCredential(userName, password);
WSManConnectionInfo ConnectionInfo = new WSManConnectionInfo(new Uri(ServerUri), SchemaUri, PSCredential);
ConnectionInfo.AuthenticationMechanism = AuthenticationMechanism.Kerberos;
Runspace RemoteRunspace = RunspaceFactory.CreateRunspace(ConnectionInfo);
PowerShell RemotePowerShell = PowerShell.Create();
RemotePowerShell.AddCommand("Enable-RemoteMailbox");
RemotePowerShell.AddParameter("Identity", samAccount);
RemotePowerShell.AddParameter("RemoteRoutingAddress", onmicrosoftemail);
// Open the remote runspace on the server.
RemoteRunspace.Open();
// Associate the runspace with the Exchange Management Shell.
RemotePowerShell.Runspace = RemoteRunspace;
var result = RemotePowerShell.Invoke();
foreach (PSObject RSLT in result)
{
back += RSLT.ToString();
}
RemoteRunspace.Close();
}
catch (Exception ex)
{
throw ex;
}
return back;
PSRemoting启用 RemotePowerShellEnabled还能够为用户 为IIS池只是一个尝试我不会让它启用 –