我寫了一個遠程訪問從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池只是一個嘗試我不會讓它啓用 –