在项目过程中会遇到需要同时设置很多台Exchange Server服务器的虚拟目录URL,图形界面设置比较麻烦。可以使用Powershell命令一下搞定。下面以设置Exchange 2013为例,其他版本的Exchange稍微修改脚本内容即可:

脚本内容如下:

1、OWA URL

检查设置是否存在问题,通过添加-whatif参数预先执行以下命令而不实际修改具体配置  
foreach($servers in (Get-OwaVirtualDirectory | where{$_.owaversion -eq "Exchange2013"})){Get-OwaVirtualDirectory -Server $servers.server | Set-OwaVirtualDirectory -InternalUrl "https://mail2010.contoso.com/owa" -ExternalUrl "https://mail2010.contoso.com/owa" -whatif}

更改配置,运行下面命令将对服务器配置进行实际更改

foreach($servers in (Get-OwaVirtualDirectory | where{$_.owaversion -eq "Exchange2013"})){Get-OwaVirtualDirectory -Server $servers.server | Set-OwaVirtualDirectory -InternalUrl "https://mail2010.contoso.com/owa" -ExternalUrl "https://mail2010.contoso.com/owa"}

2、ECP URL

检查设置是否存在问题,通过添加-whatif参数预先执行以下命令而不实际修改具体配置

foreach($servers in (Get-OwaVirtualDirectory | where{$_.owaversion -eq "Exchange2013"})){Get-ecpVirtualDirectory -Server $servers.server | Set-ecpVirtualDirectory -InternalUrl "https://mail2010.contoso.com/ecp" -ExternalUrl "https://mail2010.contoso.com/ecp" -whatif}

更改配置,运行下面命令将对服务器配置进行实际更改

foreach($servers in (Get-OwaVirtualDirectory | where{$_.owaversion -eq "Exchange2013"})){Get-ecpVirtualDirectory -Server $servers.server | Set-ecpVirtualDirectory -InternalUrl "https://mail2010.contoso.com/ecp" -ExternalUrl "https://mail2010.contoso.com/ecp"}

3、EWS URL

检查设置是否存在问题,通过添加-whatif参数预先执行以下命令而不实际修改具体配置  
foreach($servers in (Get-OwaVirtualDirectory | where{$_.owaversion -eq "Exchange2013"})){Get-WebServicesVirtualDirectory -Server $servers.server | Set-WebServicesVirtualDirectory -InternalUrl "https://mail2010.contoso.com/ews/exchange.asmx" -ExternalUrl "https://mail2010.contoso.com/ews/exchange.asmx" -whatif}

更改配置,运行下面命令将对服务器配置进行实际更改

foreach($servers in (Get-OwaVirtualDirectory | where{$_.owaversion -eq "Exchange2013"})){Get-WebServicesVirtualDirectory -Server $servers.server | Set-WebServicesVirtualDirectory -InternalUrl "https://mail2010.contoso.com/ews/exchange.asmx" -ExternalUrl "https://mail2010.contoso.com/ews/exchange.asmx"}

4、OAB URL

检查设置是否存在问题,通过添加-whatif参数预先执行以下命令而不实际修改具体配置  
foreach($servers in (Get-OwaVirtualDirectory | where{$_.owaversion -eq "Exchange2013"})){Get-OabVirtualDirectory -Server $servers.server | Set-OabVirtualDirectory -InternalUrl "https://mail2010.contoso.com/OAB" -ExternalUrl "https://mail2010.contoso.com/OAB" -whatif}

更改配置,运行下面命令将对服务器配置进行实际更改

foreach($servers in (Get-OwaVirtualDirectory | where{$_.owaversion -eq "Exchange2013"})){Get-OabVirtualDirectory -Server $servers.server | Set-OabVirtualDirectory -InternalUrl "https://mail2010.contoso.com/OAB" -ExternalUrl "https://mail2010.contoso.com/OAB"}

5、Powershell URL

检查设置是否存在问题,通过添加-whatif参数预先执行以下命令而不实际修改具体配置  
foreach($servers in (Get-OwaVirtualDirectory | where{$_.owaversion -eq "Exchange2013"})){Get-PowerShellVirtualDirectory -Server $servers.server | Set-PowerShellVirtualDirectory -InternalUrl "https://mail2010.contoso.com/Powershell" -ExternalUrl "https://mail2010.contoso.com/Powershell" -whatif}

更改配置,运行下面命令将对服务器配置进行实际更改

foreach($servers in (Get-OwaVirtualDirectory | where{$_.owaversion -eq "Exchange2013"})){Get-PowerShellVirtualDirectory -Server $servers.server | Set-PowerShellVirtualDirectory -InternalUrl "https://mail2010.contoso.com/Powershell" -ExternalUrl "https://mail2010.contoso.com/Powershell"}

6、ActiveSyncVirtualDirectory   URL

检查设置是否存在问题,通过添加-whatif参数预先执行以下命令而不实际修改具体配置  
foreach($servers in (Get-OwaVirtualDirectory | where{$_.owaversion -eq "Exchange2013"})){Get-ActiveSyncVirtualDirectory -Server $servers.server | Set-ActiveSyncVirtualDirectory -InternalUrl "https://mail2010.contoso.com/Microsoft-Server-ActiveSync" -ExternalUrl "https://mail2010.contoso.com/Microsoft-Server-ActiveSync" -whatif}

更改配置,运行下面命令将对服务器配置进行实际更改

foreach($servers in (Get-OwaVirtualDirectory | where{$_.owaversion -eq "Exchange2013"})){Get-ActiveSyncVirtualDirectory -Server $servers.server | Set-ActiveSyncVirtualDirectory -InternalUrl "https://mail2010.contoso.com/Microsoft-Server-ActiveSync" -ExternalUrl "https://mail2010.contoso.com/Microsoft-Server-ActiveSync"}