使用PowerShell连接到Exchange服务器

时间:2018-01-18 13:50:48

标签: powershell

我尝试运行以下脚本来连接到Exchange服务器,但是我收到以下错误。脚本有什么问题吗?服务器端是否有任何更改?

Get-ExecutionPolicy
Set-ExecutionPolicy RemoteSigned
$LiveCred = Get-Credential
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://mail.company.tld/powershell/ -Credential $LiveCred -Authentication Basic -AllowRedirection

错误:

New-PSSession : [mail.deloitte.ca] Connecting to remote server mail.deloitte.ca failed with the following error message : The WinRM client sent a request to an HTTP 
server and got a response saying the requested HTTP URL was not available. This is usually returned by a HTTP server that does not support the WS-Management protocol. 
For more information, see the about_Remote_Troubleshooting Help topic.
At line:4 char:12
+ $Session = New-PSSession -ConfigurationName Microsoft.Exchange -Conne ...
+            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : OpenError: (System.Manageme....RemoteRunspace:RemoteRunspace) [New-PSSession], PSRemotingTransportException
    + FullyQualifiedErrorId : URLNotAvailable,PSSessionOpenFailed

2 个答案:

答案 0 :(得分:0)

您是否按照this document中的说明检查了PowerShellVirtualDirectory?它提到完全相同的问题。

答案 1 :(得分:0)

假设您的ConnectionUri正确,很可能在目标CAS服务器上未启用PowerShell远程处理。您可以直接在CAS服务器上运行它来启用它:

Enable-PSRemoting

可能还需要使用以下命令配置PowerShell虚拟目录:

Set-PowerShellVirtualDirectory "[ServerName]\POWERSHELL (default web site)" -BasicAuthentication $true