SCRIPT: InternalExternalURLs.ps1

Script Name: Set-InternalExternalURLs.ps1

Script Author: Ståle Hansen

Original Post: https://msunified.net/2010/05/07/script-for-configuring-exchange-2010-internal-and-external-urls/

Log:

  • v01 07.05.2010
    • Initial Script. Sets internal, external and Exchange 2003 URLs.
    • Assumes that CASarray is deployed in singel ADsite for internal URL.
    • This script is created for an Exchange 2003 coexistence\migration scenario
  • v02 27.05.2010
    • Added support for Exchange 2007 and Exchange 2007/2010 coexistence scenarios.
    • The script will check for Exchange version before applying any settings.
    • When applying Exchange 2010 Internal URL the script will match the CAS servers to the correct CASarray in the correct ADsite
  • v03 28.05.2010
    • Added option for checking current configuration
    • Corrected some errors on the Exchange 2007 configuration and listing of URLs
    • Tested in Exchange 2007 only deployments and Exchange 2010 and 2007 coexistence deployments
  • v04 13.05.2011
    • Removed the dependency on CAS Array for internal URL
    • It is not recommended to have the same name for cas array and internal/external url
    • It is now set after input

Code:

####################################################################################################
# Set-InternalExternalURLs.ps1
#
# v04 May2011 by Ståle Hansen (http://msunified.net)
#
# Idea from MVP's Anderson Patricio and Pat Richard, script designed for Exchange 2010 prerequisites
# Thanks to Marjus Sirvinsks for adapting the script further
#
####################################################################################################
[System.Console]::ForegroundColor = [System.ConsoleColor]::White
clear-host

	write-host
	write-host Script for setting Internal and External URLs on Exchange 2007/2010
	write-host
	write-host Please choose one of the following:
	write-host
	write-host '1) Exchange 2010 Internal URLs'
	write-host '2) Exchange 2010 External URLs'
	write-host '3) Exchange 2007 Internal URLs'
	write-host '4) Exchange 2007 External URLs'
	write-host '5) Exchange 2003 Legacy URL'
	write-host '6) List Current URL Config'
	write-host '7) Cancel' -ForegroundColor Red
	write-host
	$opt = Read-Host "Select an option [1-7]"

switch ($opt)    {

1{
# Set internal URL on all Exchange 2010 Client Access Servers using input

Foreach($Server in Get-ClientAccessServer | Get-ExchangeServer | where-object {$_.AdminDisplayVersion.Major -eq 14}){
$CASserver = $Server.Identity
$ADsite = Get-ExchangeServer $Server
$site = $ADsite.site

Write-Host
Write-Host "Found Exchange 2010 Client Access Server " -NoNewLine
Write-Host $CASserver -NoNewLine -Foregroundcolor Green
Write-Host " in ADsite " -NoNewLine
Write-Host $site -Foregroundcolor Green
Write-Host

}

$urlpath = Read-Host "Type internal FQDN for Exchange 2010 Client Access (without https://)"
Write-Host "Will set InternalUrl as " -NoNewLine
Write-Host "https://$urlpath/" -NoNewLine -foregroundcolor Green
Write-Host " on all Exchange 2010 Client Access Servers"

Write-Host
Write-Host "Press " -NoNewLine
Write-Host "Enter" -NoNewLine -foregroundcolor Green
Write-Host " to continue, or " -NoNewLine
Write-Host "CTR+C " -NoNewLine -foregroundcolor Red
Write-Host "to cancel"
[System.Console]::ForegroundColor = [System.ConsoleColor]::Gray
Read-Host
[System.Console]::ForegroundColor = [System.ConsoleColor]::White

Foreach($Server in Get-ClientAccessServer | Get-ExchangeServer | where-object {$_.AdminDisplayVersion.Major -eq 14}){
$CASserver = $Server.Identity

Get-AutodiscoverVirtualDirectory -Server $CASserver | Set-AutodiscoverVirtualDirectory –InternalUrl "https://$urlpath/Autodiscover/Autodiscover.xml"
Get-ClientAccessServer -Identity $CASserver | Set-ClientAccessServer –AutodiscoverServiceInternalUri "https://$urlpath/Autodiscover/Autodiscover.xml"
Get-WebservicesVirtualDirectory -Server $CASserver | Set-WebservicesVirtualDirectory –InternalUrl "https://$urlpath/Ews/Exchange.asmx"
Get-OabVirtualDirectory -Server $CASserver | Set-OabVirtualDirectory –InternalUrl "https://$urlpath/Oab"
Get-OwaVirtualDirectory -Server $CASserver | Set-OwaVirtualDirectory –InternalUrl "https://$urlpath/Owa"
Get-EcpVirtualDirectory -Server $CASserver | Set-EcpVirtualDirectory –InternalUrl "https://$urlpath/Ecp"
Get-ActiveSyncVirtualDirectory -Server $CASserver | Set-ActiveSyncVirtualDirectory -InternalUrl "https://$urlpath/Microsoft-Server-ActiveSync"
}

#Get commands to doublecheck the config
[System.Console]::ForegroundColor = [System.ConsoleColor]::White

Get-AutodiscoverVirtualDirectory | ft Identity,InternalUrl
Get-ClientAccessServer | ft Identity,AutodiscoverServiceInternalUri
Get-WebservicesVirtualDirectory | ft Identity,InternalUrl
Get-OabVirtualDirectory | ft Identity,InternalUrl
Get-OwaVirtualDirectory | ft Identity,InternalUrl
Get-EcpVirtualDirectory | ft Identity,InternalUrl
Get-ActiveSyncVirtualDirectory | ft Identity,InternalUrl

[System.Console]::ForegroundColor = [System.ConsoleColor]::Gray

}

2{
# Set external URL on all Exchange 2010 Client Access Servers using input

Foreach($Server in Get-ClientAccessServer | Get-ExchangeServer | where-object {$_.AdminDisplayVersion.Major -eq 14}){
$CASserver = $Server.Identity
$ADsite = Get-ExchangeServer $Server
$site = $ADsite.site

Write-Host
Write-Host "Found Exchange 2010 Client Access Server " -NoNewLine
Write-Host $CASserver -NoNewLine -Foregroundcolor Green
Write-Host " in ADsite " -NoNewLine
Write-Host $site -Foregroundcolor Green
Write-Host

}

$urlpath = Read-Host "Type external FQDN for Exchange 2010 Client Access (without https://)"
Write-Host "Will set ExternalUrl as " -NoNewLine
Write-Host "https://$urlpath/" -NoNewLine -foregroundcolor Green
Write-Host " on all Exchange 2010 Client Access Servers"

Write-Host
Write-Host "Press " -NoNewLine
Write-Host "Enter" -NoNewLine -foregroundcolor Green
Write-Host " to continue, or " -NoNewLine
Write-Host "CTR+C " -NoNewLine -foregroundcolor Red
Write-Host "to cancel"
[System.Console]::ForegroundColor = [System.ConsoleColor]::Gray
Read-Host
[System.Console]::ForegroundColor = [System.ConsoleColor]::White

Foreach($Server in Get-ClientAccessServer | Get-ExchangeServer | where-object {$_.AdminDisplayVersion.Major -eq 14}){
$CASserver = $Server.Identity

Get-AutodiscoverVirtualDirectory -Server $CASserver | Set-AutodiscoverVirtualDirectory –ExternalUrl "https://$urlpath/Autodiscover/Autodiscover.xml"
Get-webservicesVirtualDirectory -Identity $CASserver | Set-webservicesVirtualDirectory –ExternalUrl "https://$urlpath/Ews/Exchange.asmx"
Get-OabVirtualDirectory -Server $CASserver | Set-OabVirtualDirectory –ExternalUrl "https://$urlpath/Oab"
Get-OwaVirtualDirectory -Server $CASserver | Set-OwaVirtualDirectory –ExternalUrl "https://$urlpath/Owa"
Get-EcpVirtualDirectory -Server $CASserver | Set-EcpVirtualDirectory –ExternalUrl "https://$urlpath/Ecp"
Get-ActiveSyncVirtualDirectory -Server $CASserver | Set-ActiveSyncVirtualDirectory -ExternalUrl "https://$urlpath/Microsoft-Server-ActiveSync"
}

#Get commands to doublecheck the config
[System.Console]::ForegroundColor = [System.ConsoleColor]::White

Get-AutodiscoverVirtualDirectory | ft Identity,ExternalUrl
Get-webservicesVirtualDirectory | ft Identity,ExternalUrl
Get-OabVirtualDirectory | ft Identity,ExternalUrl
Get-OwaVirtualDirectory | ft Identity,ExternalUrl
Get-EcpVirtualDirectory | ft Identity,ExternalUrl
Get-ActiveSyncVirtualDirectory | ft Identity,ExternalUrl

[System.Console]::ForegroundColor = [System.ConsoleColor]::Gray

}

3{
# Set Exchange 2007 Internal URLs using input

Foreach($Server in Get-ClientAccessServer | Get-ExchangeServer | where-object {$_.AdminDisplayVersion.Major -lt 14}){
$CASserver = $Server.Identity
$ADsite = Get-ExchangeServer $Server
$site = $ADsite.site

Write-Host
Write-Host "Found Exchange 2007 Client Access Server " -NoNewLine
Write-Host $CASserver -NoNewLine -Foregroundcolor Green
Write-Host " in ADsite " -NoNewLine
Write-Host $site -Foregroundcolor Green
Write-Host

}

Write-Host "Type internal FQDN for Exchange 2007 Client Access"
Write-Host "Please type http:// or https:// in front: " -NoNewLine -foregroundcolor Yellow
$urlpath = Read-Host
Write-Host
Write-Host "Will set InternalUrl as " -NoNewLine
Write-Host "$urlpath/" -NoNewLine -foregroundcolor Green
Write-Host " on all Exchange 2007 Client Access Servers"

Write-Host
Write-Host "Press " -NoNewLine
Write-Host "Enter" -NoNewLine -foregroundcolor Green
Write-Host " to continue, or " -NoNewLine
Write-Host "CTR+C " -NoNewLine -foregroundcolor Red
Write-Host "to cancel"
[System.Console]::ForegroundColor = [System.ConsoleColor]::Gray
Read-Host
[System.Console]::ForegroundColor = [System.ConsoleColor]::White

Foreach($Server in Get-ClientAccessServer | Get-ExchangeServer | where-object {$_.AdminDisplayVersion.Major -lt 14}){
$CASserver = $Server.Identity

Get-AutodiscoverVirtualDirectory -Server $CASserver | Set-AutodiscoverVirtualDirectory –InternalUrl "$urlpath/Autodiscover/Autodiscover.xml"
Get-ClientAccessServer -Identity $CASserver | Set-ClientAccessServer –AutodiscoverServiceInternalUri "$urlpath/Autodiscover/Autodiscover.xml"
Get-WebservicesVirtualDirectory -Server $CASserver | Set-WebservicesVirtualDirectory –InternalUrl "$urlpath/Ews/Exchange.asmx"
Get-OabVirtualDirectory -Server $CASserver | Set-OabVirtualDirectory –InternalUrl "$urlpath/Oab"
Get-OwaVirtualDirectory -Identity "$CASserver\OWA (Default Web site)"  | Set-OwaVirtualDirectory –InternalUrl "$urlpath/Owa"
Get-ActiveSyncVirtualDirectory -Server $CASserver | Set-ActiveSyncVirtualDirectory -InternalUrl "$urlpath/Microsoft-Server-ActiveSync"
}

#Get commands to doublecheck the config
[System.Console]::ForegroundColor = [System.ConsoleColor]::White

Get-AutodiscoverVirtualDirectory | ft Identity,InternalUrl
Get-ClientAccessServer | ft Identity,AutodiscoverServiceInternalUri
Get-WebservicesVirtualDirectory | ft Identity,InternalUrl
Get-OabVirtualDirectory | ft Identity,InternalUrl
Get-OwaVirtualDirectory | ft Identity,InternalUrl
Get-ActiveSyncVirtualDirectory | ft Identity,InternalUrl

[System.Console]::ForegroundColor = [System.ConsoleColor]::Gray

}

4{
# Set external URL on Exchange 2007 Client Access Servers using input

Foreach($Server in Get-ClientAccessServer | Get-ExchangeServer | where-object {$_.AdminDisplayVersion.Major -lt 14}){
$CASserver = $Server.Identity
$ADsite = Get-ExchangeServer $Server
$site = $ADsite.site

Write-Host
Write-Host "Found Exchange 2007 Client Access Server " -NoNewLine
Write-Host $CASserver -NoNewLine -Foregroundcolor Green
Write-Host " in ADsite " -NoNewLine
Write-Host $site -Foregroundcolor Green
Write-Host
}

$urlpath = Read-Host "Type external FQDN for Client Access"
Write-Host "Will set ExternalUrl as " -NoNewLine
Write-Host "https://$urlpath/" -NoNewLine -foregroundcolor Green
Write-Host " on all Exchange 2007 Client Access Servers"

Write-Host
Write-Host "Press " -NoNewLine
Write-Host "Enter" -NoNewLine -foregroundcolor Green
Write-Host " to continue, or " -NoNewLine
Write-Host "CTR+C " -NoNewLine -foregroundcolor Red
Write-Host "to cancel"
[System.Console]::ForegroundColor = [System.ConsoleColor]::Gray
Read-Host
[System.Console]::ForegroundColor = [System.ConsoleColor]::White

Foreach($Server in Get-ClientAccessServer | Get-ExchangeServer | where-object {$_.AdminDisplayVersion.Major -lt 14}){
$CASserver = $Server.Identity

Get-AutodiscoverVirtualDirectory -Server $CASserver | Set-AutodiscoverVirtualDirectory –ExternalUrl "https://$urlpath/Autodiscover/Autodiscover.xml"
Get-webservicesVirtualDirectory -Server $CASserver | Set-webservicesVirtualDirectory –ExternalUrl "https://$urlpath/Ews/Exchange.asmx"
Get-OabVirtualDirectory -Server $CASserver | Set-OabVirtualDirectory –ExternalUrl "https://$urlpath/Oab"
Get-OwaVirtualDirectory -Identity "$CASserver\OWA (Default Web site)" | Set-OwaVirtualDirectory –ExternalUrl "https://$urlpath/Owa"
Get-ActiveSyncVirtualDirectory -Server $CASserver | Set-ActiveSyncVirtualDirectory -ExternalUrl "https://$urlpath/Microsoft-Server-ActiveSync"

}

#Get commands to doublecheck the config
[System.Console]::ForegroundColor = [System.ConsoleColor]::White

Get-AutodiscoverVirtualDirectory | ft Identity,ExternalUrl
Get-webservicesVirtualDirectory | ft Identity,ExternalUrl
Get-OabVirtualDirectory | ft Identity,ExternalUrl
Get-OwaVirtualDirectory | ft Identity,ExternalUrl
Get-ActiveSyncVirtualDirectory | ft Identity,ExternalUrl

[System.Console]::ForegroundColor = [System.ConsoleColor]::Gray

}

5{
$legacy = Read-Host "For Legacy Exchange 2003 coexistence, type external FQDN"
Write-Host "Will use" -NoNewLine
Write-Host " https://$legacy/Exchange" -NoNewLine -foregroundcolor Green
Write-Host " as Exchange 2003 URL on all Exchange 2010 Client Access Servers"

Write-Host
Write-Host "Press " -NoNewLine
Write-Host "Enter" -NoNewLine -foregroundcolor Green
Write-Host " to continue, or " -NoNewLine
Write-Host "CTR+C " -NoNewLine -foregroundcolor Red
Write-Host "to cancel"
[System.Console]::ForegroundColor = [System.ConsoleColor]::Gray
Read-Host
[System.Console]::ForegroundColor = [System.ConsoleColor]::White

Foreach($Server in Get-ClientAccessServer | Get-ExchangeServer | where-object {$_.AdminDisplayVersion.Major -eq 14}){
$CASserver = $Server.Identity

Get-OwaVirtualDirectory -Server $CASserver | Set-OwaVirtualDirectory –Exchange2003Url "https://$legacy/Exchange"

}

#get command to doublecheck the config
[System.Console]::ForegroundColor = [System.ConsoleColor]::White

Get-OwaVirtualDirectory | ft Identity,Exchange2003Url

[System.Console]::ForegroundColor = [System.ConsoleColor]::Gray

}

6{
# Display current Exchange Internal and External URL configuration
# Testing if Exchange 2010 servers present, if not dont display ECP else display with ECP

$Server = Get-ClientAccessServer | Get-ExchangeServer | where-object {$_.AdminDisplayVersion.Major -eq 14}
if ($server -eq $Null){

# No Exchange 2010 servers present

Get-AutodiscoverVirtualDirectory | fl Identity,InternalUrl,ExternalUrl
Get-ClientAccessServer | fl Identity,AutodiscoverServiceInternalUri
Get-WebservicesVirtualDirectory | fl Identity,InternalUrl,ExternalUrl
Get-OabVirtualDirectory | fl Identity,InternalUrl,ExternalUrl
Get-OwaVirtualDirectory | fl Identity,InternalUrl,ExternalUrl
Get-ActiveSyncVirtualDirectory | fl Identity,InternalUrl,ExternalUrl

[System.Console]::ForegroundColor = [System.ConsoleColor]::Gray
}
else{

# Exchange 2010 servers present

Get-AutodiscoverVirtualDirectory | fl Identity,InternalUrl,ExternalUrl
Get-ClientAccessServer | fl Identity,AutodiscoverServiceInternalUri
Get-WebservicesVirtualDirectory | fl Identity,InternalUrl,ExternalUrl
Get-OabVirtualDirectory | fl Identity,InternalUrl,ExternalUrl
Get-OwaVirtualDirectory | fl Identity,InternalUrl,ExternalUrl,Exchange2003Url
Get-EcpVirtualDirectory | fl Identity,InternalUrl,ExternalUrl
Get-ActiveSyncVirtualDirectory | fl Identity,InternalUrl,ExternalUrl

[System.Console]::ForegroundColor = [System.ConsoleColor]::Gray

}
}

7{

[System.Console]::ForegroundColor = [System.ConsoleColor]::Gray

}
		}

24 thoughts on “SCRIPT: InternalExternalURLs.ps1

    • I handle lots of Exchange servers and this script is really useful. It allows me to change all the URL’s to match the SSL name easily and accurately every time.

      Thanks,
      Paul

  1. When I launch the script in PS I get “The term ‘Get-clientaccessserver’ is not recognized as the name of a cmdlet and the same goes for all the other commands ?
    also if I type it manually

    What am i doing wrong ?
    thanks

  2. Hi Lars, thanks for commenting. This script need to be run in Exchange Managament Shell on Exchange 2007 or Exchange 2010. I recon you are using the native PowerShell command windows and not the Exchange one?

    Regards
    Ståle

  3. Hi Ståle,
    Just returned from vacation and apparently i didnt receive an email that youve answered my question.
    You were right I was running it in Powershell now much better in EMS thank you.!!

    however I get these erros:
    Cannot process argument transformation on parameter ‘InternalUrl’. Cannot convert value “https:///Autodiscover/Autodisc
    over.xml” to type “System.Uri”. Error: “Invalid URI: The hostname could not be parsed.”

    My actual problem is that I get an security alert when i autoconfigure outlook clients saying the certificate is not trusted I have a cert. from trusted provider I use for webmail but the autodiscover also points to “servername.domain.local” instead of “webmail.domain.com” so I think I need to change the “AutoDiscoverServiceInternalUri” from “https://servername.domain.local/Autodiscover/Autodisc..” to “”https://webmail.domain.com/Autodiscover/Autodisc..”

    do you have any idea.. ?
    thank you for answering so far!

  4. ok I hear you I will make the array, ive got the cert issue solved by typing NETBIOSSRV.fqdn so Ive got the users off my back for now.
    thank you!!!
    I will post when I have made the ARRAY and run the script
    Lars

  5. One quick question? Does this configure URL for local site or all sites within the Exchange org. I would like to have different URL for each geographically seperated internet facing sites.

    • I don’t think so, you need to run the commands manually for each site. Should be an easy task to rewrite the script to work in different AD sites though.

  6. Awesome script! I have a suggestion, though. Is there anyway you can add the ability to choose what servers/sites to apply the changes to? It finds ALL servers in ALL sites, and it appears to be aware of what site they reside in, so I would think it would be easy to take the $site value gathered on line 036 and use it to pass these commands to. For instance, take the $ADsite.site returned from each server, allow it to be chosen and saved to $selectedsite, and then pass it to the commands like “Set-ClientAccessServer -Identity $CASserver -AutoDiscoverServiceInternalUri “https://$urlsite/autodiscover/autodiscover.xml” -AutoDiscoverSiteScope $selectedsite”

    I’m no programmer, but I can understand what it’s doing, so I may be oversimplifying it, but this option is really needed.

    THANKS!

  7. Hi there,

    Script looks great. Call be a novice but how I do I get copy of this. If I copy and paste the script then all the line numbers are also incorporated?

    CW

    • Hi, if you mouseover the scriptfeild you will get a copy function in the top right corner. That should allow you to copy or open the script in a view without the numbers

      /Ståle

  8. Just wanted to let you know that this script resolved an issue that has been around since the migration from Exchange 2003, The interface would load but on our plant PC”s that have restricted Internet access (Invalid Proxy Server for anything not internal). The global address list and the message body would take several mnutes to load if at all. The EWS and Autodiscovery for Internal URL’s were pointed to the outside. One change to the internal URL and everything works great…!!!!!!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s