林使用PowerShell試圖訪問在C# 這裏使用PowerShell中的Exchange服務器的代碼我試圖使用訪問Exchange在C#
WSManConnectionInfo ConnectionInfo = new WSManConnectionInfo(new Uri(@"http://myexchangeserver.com"), "http://schemas.microsoft.com/powershell/Microsoft.Exchange", (PSCredential)null);
ConnectionInfo.AuthenticationMechanism = AuthenticationMechanism.Kerberos;
using (Runspace runspace = RunspaceFactory.CreateRunspace(ConnectionInfo))
{
using (PowerShell PS_Instance = PowerShell.Create())
{
PS_Instance.AddCommand("Get-MailboxPermission -Identity UAT_TestGeneric");
runspace.Open();
PS_Instance.Runspace = runspace;
Collection<PSObject> results = PS_Instance.Invoke();
if (PS_Instance.Streams.Error.Count > 0)
{
//Couldnt Connect To Server
}
else
{
//Do Stuff
}
}
我不斷收到此錯誤信息
的WinRM客戶端從遠程的 WS管理服務收到HTTP狀態碼403。有關更多信息,請參閱 about_Remote_Troubleshooting幫助主題。
我已經檢查了exchange服務器的powershell IIS文件夾,它不需要SSL,如https://support.microsoft.com/en-au/kb/2276957所示。
有沒有可以提供幫助的人? 謝謝。
您可能想嘗試使用Powershell首先進行連接,以測試您是否具有正確的先決條件並檢查Auth是否正確等https: //technet.microsoft.com/en-us/library/dd297932(v=exchg.141).aspx –