In my career, I have to be able to be efficient as most of my projects are on a time crunch schedule. Being able to quickly configure Exchange when setting up a server environment is crucial to the success of the project.
While still honing my skills in PowerShell, I was attempting to create my own script to help configure all of the Virtual Directories in one shot rather than go to each setting and configure them manually. It did not go very well, so as I do, I research and find great professionals that do great work in scripting so that I may learn from them.
In doing so, I found Paul Cunningham’s script that performs this. I took the following script and modified it to add the PowerShell Virtual Directory to it as I like to configure that as well.
***YOU CAN REM THE LINES OUT SHOULD YOU NOT WANT TO CONFIGURE THAT DIRECTORY***
Here is my version of the script:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 | <# .SYNOPSIS ConfigureExchangeURLs.ps1 .DESCRIPTION PowerShell script to configure the Client Access server URLs for Microsoft Exchange Server 2013/2016. All Client Access server URLs will be set to the same namespace. If you are using separate namespaces for each CAS service this script will not handle that. The script sets Outlook Anywhere to use NTLM with SSL required by default. If you have different auth requirements for Outlook Anywhere use the optional parameters to set those. .PARAMETER Server The name(s) of the server(s) you are configuring. .PARAMETER InternalURL The internal namespace you are using. .PARAMETER ExternalURL The external namespace you are using. .PARAMETER InternalSSL Specifies the internal SSL requirement for Outlook Anywhere. Defaults to True (SSL required). .PARAMETER ExternalSSL Specifies the external SSL requirement for Outlook Anywhere. Defaults to True (SSL required). .EXAMPLE .\ConfigureExchangeURLs.ps1 -Server sydex1 -InternalURL mail.exchangeserverpro.net -ExternalURL mail.exchangeserverpro.net .EXAMPLE .\ConfigureExchangeURLs.ps1 -Server sydex1,sydex2 -InternalURL mail.exchangeserverpro.net -ExternalURL mail.exchangeserverpro.net .LINK http://exchangeserverpro.com/powershell-script-configure-exchange-urls/ .NOTES Written by: Paul Cunningham For more Exchange Server tips, tricks and news check out Exchange Server Pro. * Website: http://exchangeserverpro.com * Twitter: http://twitter.com/exchservpro Find me on: * My Blog: http://paulcunningham.me * Twitter: https://twitter.com/paulcunningham * LinkedIn: http://au.linkedin.com/in/cunninghamp/ * Github: https://github.com/cunninghamp License: The MIT License (MIT) Copyright (c) 2015 Paul Cunningham Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. Change Log: V1.00, 13/11/2014 - Initial version V1.01, 26/06/2015 - Added MAPI/HTTP URL configuration V1.02, 27/08/2015 - Improved error handling, can now specify multiple servers to configure at once. V1.03, 09/09/2015 - ExternalURL can now be $null V1.04, 17/11/2016 - Removed Outlook Anywhere auth settings, script now sets URLs only V1.05, 18/11/2016 - Added AutodiscoverSCP option so it can be set to a different URL than other services V1.06, 25/06/2019 - Added PowerShell Virtual Directory Configuration Requiring SSL and using Basic Authentication .ADDENDUM V1.06 Modified by Lance Lingerfelt for similar use. * Website: http://www.ldlnet.net * IT Blog: http://itblog.ldlnet.net #> #requires -version 2 [CmdletBinding()] param( [Parameter( Position=0,Mandatory=$true)] [string[]]$Server, [Parameter( Mandatory=$true)] [string]$InternalURL, [Parameter( Mandatory=$true)] [AllowEmptyString()] [string]$ExternalURL, [Parameter( Mandatory=$false)] [string]$AutodiscoverSCP, [Parameter( Mandatory=$false)] [Boolean]$InternalSSL=$true, [Parameter( Mandatory=$false)] [Boolean]$ExternalSSL=$true ) #................................... # Script #................................... Begin { #Add Exchange snapin if not already loaded in the PowerShell session if (Test-Path $env:ExchangeInstallPath\bin\RemoteExchange.ps1) { . $env:ExchangeInstallPath\bin\RemoteExchange.ps1 Connect-ExchangeServer -auto -AllowClobber } else { Write-Warning "Exchange Server management tools are not installed on this computer." EXIT } } Process { foreach ($i in $server) { if ((Get-ExchangeServer $i -ErrorAction SilentlyContinue).IsClientAccessServer) { Write-Host "----------------------------------------" Write-Host " Configuring $i" Write-Host "----------------------------------------`r`n" Write-Host "Values:" Write-Host " - Internal URL: $InternalURL" Write-Host " - External URL: $ExternalURL" Write-Host " - Outlook Anywhere internal SSL required: $InternalSSL" Write-Host " - Outlook Anywhere external SSL required: $ExternalSSL" Write-Host "`r`n" Write-Host "Configuring Outlook Anywhere URLs" $OutlookAnywhere = Get-OutlookAnywhere -Server $i $OutlookAnywhere | Set-OutlookAnywhere -ExternalHostname $externalurl -InternalHostname $internalurl ` -ExternalClientsRequireSsl $ExternalSSL -InternalClientsRequireSsl $InternalSSL ` -ExternalClientAuthenticationMethod $OutlookAnywhere.ExternalClientAuthenticationMethod if ($externalurl -eq "") { Write-Host "Configuring Outlook Web App URLs" Get-OwaVirtualDirectory -Server $i | Set-OwaVirtualDirectory -ExternalUrl $null -InternalUrl https://$internalurl/owa Write-Host "Configuring Exchange Control Panel URLs" Get-EcpVirtualDirectory -Server $i | Set-EcpVirtualDirectory -ExternalUrl $null -InternalUrl https://$internalurl/ecp Write-Host "Configuring ActiveSync URLs" Get-ActiveSyncVirtualDirectory -Server $i | Set-ActiveSyncVirtualDirectory -ExternalUrl $null -InternalUrl https://$internalurl/Microsoft-Server-ActiveSync Write-Host "Configuring Exchange Web Services URLs" Get-WebServicesVirtualDirectory -Server $i | Set-WebServicesVirtualDirectory -ExternalUrl $null -InternalUrl https://$internalurl/EWS/Exchange.asmx Write-Host "Configuring Offline Address Book URLs" Get-OabVirtualDirectory -Server $i | Set-OabVirtualDirectory -ExternalUrl $null -InternalUrl https://$internalurl/OAB Write-Host "Configuring MAPI/HTTP URLs" Get-MapiVirtualDirectory -Server $i | Set-MapiVirtualDirectory -ExternalUrl $null -InternalUrl https://$internalurl/mapi Write-Host "Configuring PowerShell URLs" Get-PowerShellVirtualDirectory -Server $i | Set-PowerShellVirtualDirectory -ExternalUrl $null -InternalUrl https://$internalurl/PowerShell -BasicAuthentication $True -RequireSSL $True -Confirm:$False } else { Write-Host "Configuring Outlook Web App URLs" Get-OwaVirtualDirectory -Server $i | Set-OwaVirtualDirectory -ExternalUrl https://$externalurl/owa -InternalUrl https://$internalurl/owa Write-Host "Configuring Exchange Control Panel URLs" Get-EcpVirtualDirectory -Server $i | Set-EcpVirtualDirectory -ExternalUrl https://$externalurl/ecp -InternalUrl https://$internalurl/ecp Write-Host "Configuring ActiveSync URLs" Get-ActiveSyncVirtualDirectory -Server $i | Set-ActiveSyncVirtualDirectory -ExternalUrl https://$externalurl/Microsoft-Server-ActiveSync -InternalUrl https://$internalurl/Microsoft-Server-ActiveSync Write-Host "Configuring Exchange Web Services URLs" Get-WebServicesVirtualDirectory -Server $i | Set-WebServicesVirtualDirectory -ExternalUrl https://$externalurl/EWS/Exchange.asmx -InternalUrl https://$internalurl/EWS/Exchange.asmx Write-Host "Configuring Offline Address Book URLs" Get-OabVirtualDirectory -Server $i | Set-OabVirtualDirectory -ExternalUrl https://$externalurl/OAB -InternalUrl https://$internalurl/OAB Write-Host "Configuring MAPI/HTTP URLs" Get-MapiVirtualDirectory -Server $i | Set-MapiVirtualDirectory -ExternalUrl https://$externalurl/mapi -InternalUrl https://$internalurl/mapi Write-Host "Configuring PowerShell URLs" Get-PowerShellVirtualDirectory -Server $i | Set-PowerShellVirtualDirectory -ExternalUrl https://$externalurl/PowerShell -InternalUrl https://$internalurl/PowerShell -BasicAuthentication $True -RequireSSL $True -Confirm:$False } Write-Host "Configuring Autodiscover" if ($AutodiscoverSCP) { Get-ClientAccessServer $i | Set-ClientAccessServer -AutoDiscoverServiceInternalUri https://$AutodiscoverSCP/Autodiscover/Autodiscover.xml } else { Get-ClientAccessServer $i | Set-ClientAccessServer -AutoDiscoverServiceInternalUri https://$internalurl/Autodiscover/Autodiscover.xml } Write-Host "`r`n" } else { Write-Host -ForegroundColor Yellow "$i is not a Client Access server." } } } End { Write-Host "Finished processing all servers specified. Consider running Get-CASHealthCheck.ps1 to test your Client Access namespace and SSL configuration." -ForegroundColor Yellow Write-Host "Refer to http://exchangeserverpro.com/testing-exchange-server-2013-client-access-server-health-with-powershell/ for more details." Write-Host "Also check out http://itblog.ldlnet.net for Lance's IT Blog of information!" -ForegroundColor Gray } #................................... # Finished #................................... |
NOTES:
- PowerShell script to configure the Client Access server URLs for Microsoft Exchange Server 2013/2016. All Client Access server URLs will be set to the same namespace.
- If you are using separate namespaces for each CAS service this script will not handle that.
- The script sets Outlook Anywhere to use NTLM with SSL required by default.
- If you have different auth requirements for Outlook Anywhere use the optional parameters to set those.
- The script sets PowerShell to use Basic with SSL required by default.
- If you have different authentication requirements for PowerShell use the optional parameters to set those.
- PowerShell was added to the settings. Please be sure to REM those lines of code should you NOT want to configure the PowerShell Virtual Directory.
USAGE:
1 | .\ConfigureExchangeURLs.ps1 -Server EX01 -InternalURL mail.ldlnet.net -ExternalURL mail.ldlnet.net |
1 | .\ConfigureExchangeURLs.ps1 -Server EX01,EX02,EX03 -InternalURL mail.ldlnet.net -ExternalURL mail.ldlnet.net |
HAPPY SCRIPTING!
POSITIVE ENERGY!
PLEASE COMMENT!
REFERENCES:
Exchange Server Client Access URL Configuration Script
PowerShell Script to Configure Exchange Server Client Access URLs