Script to set InternalURL and ExternalURL for all Exchange 2010 Virtual Directories

I’ve been working recently on a series of articles describing how to get Exchange 2010 up and running on a single server.

The aim is to provide small IT shops or those getting started with Exchange 2010 a place to come where they can find out all about the steps needed to get a server operational without having to first wade through the massive help file!

That’s not to say the help file isn’t useful. It is! very very useful. It’s just rather large and intimidating.

In the course of this article, I’ve found that although Exchange 2010 makes more available in the GUI than Exchange 2007 did, there is still not the automation that would make things easy.

For example, when you create a new certificate in the nice new GUI, you enter a whole bunch of information which could then be used to set the relevant URL settings on the multitude of Exchange related virtual directories needed to make things like OWA work properly.

So I started to dig around and found a great script. It started out on the Exchange Ninjas site for Exchange 2007:

http://www.exchangeninjas.com/set-allvdirs

Then another chap got involved and started updating for Exchange 2010:

http://virtualbarrymartin.me/2009/12/29/how-to-setup-exchange-2010-to-use-a-single-certificate-for-internal-and-external-use/

However, he missed a couple of bits, like leaving in the UM virtual directory and not entering the ActiveSync or PowerShell directories. He also didn’t set the OAB to require or not SSL based upon the use of a public certificate.

I’ve fixed those bits and now present the following script which can set all relevant Exchange 2010 virtual directory URLs (both Internal and External) based around a single Exchange 2010 server being connected to the Internet to provide service for a site.

Over time I will probably add more functionality like the ability to set OWA logon type to the email address format (UPN) rather than domain\username.

Hope you find this useful, and more than happy to hear of any improvements that could be made.

Cheers

Nathan

 

# Script to allow you to set all virtual directories to a common name like mail.company.com

Start-Transcript

# Variables

[string]$EASExtend = “/Microsoft-Server-ActiveSync”
[string]$PShExtend = “/powershell”
[string]$OWAExtend = “/OWA”
[string]$OABExtend = “/OAB”
[string]$SCPExtend = “/Autodiscover/Autodiscover.xml”
[string]$EWSExtend = “/EWS/Exchange.asmx”
[string]$ECPExtend = “/ECP”
[string]$ConfirmPrompt = “Set this Value? (Y/N)”
[string]$NoChangeForeground = “white”
[string]$NoChangeBackground = “red”

Write-host “This will allow you to set the virtual directories associated with setting up a single SSL certificate to work with Exchange 2010.”
Write-host “”
[string]$base = Read-host “Base name of virtual directory (e.g. mail.company.com)”
write-host “”

# =============================================
# Validate if a third party trusted certificate is being used
# because BITS used by OAB downloads won’t use untrusted certificates
[string]$set = Read-host “Is the certificate being used an internally generated certificate? (Y/N)”
Write-host “”

if ($set -eq “Y”)    {
    [string]$OABprefix = “http://”
    [boolean]$OABRequireSSL = $false
}    else    {
    [string]$OABprefix = “https://”
    [boolean]$OABRequireSSL = $true
}

# =============================================
# Build the OAB URL and set the internal Value

Write-host “Setting OAB Virtual Directories” -foregroundcolor Yellow
write-host “”

$OABURL = $OABprefix + $base + $OABExtend

[array]$OABCurrent = Get-OABVirtualDirectory

Foreach ($value in $OABcurrent) {
    Write-host “Looking at Server: ” $value.server
    Write-host “Current Internal Value: ” $value.internalURL
    Write-host “New Internal Value:     ” $OABUrl
    [string]$set = Read-host $ConfirmPrompt
    write-host “”

    if ($set -eq “Y”)    {
        Set-OABVirtualDirectory -id $value.identity -InternalURL $OABURL -RequireSSL:$OABRequireSSL
    } else {
        write-host “OAB Virtual Directory internal value NOT changed” -foregroundcolor $NoChangeForeground -backgroundcolor $NoChangeBackground
    }

    Write-host “Looking at Server: ” $value.server
    Write-host “Current External Value: ” $value.externalURL
    Write-host “New External Value:     ” $OABUrl
    [string]$set = Read-host $ConfirmPrompt
    write-host “”

    if ($set -eq “Y”) {
        Set-OABVirtualDirectory -id $value.identity -ExternalURL $OABURL -RequireSSL:$OABRequireSSL
    } else {
        write-host “OAB Virtual Directory external value NOT changed” -foregroundcolor $NoChangeForeground -backgroundcolor $NoChangeBackground
    }
}

# ============================================
# Build the Autodiscover URL and set the SCP Value

Write-host “Setting Autodiscover Service Connection Point” -foregroundcolor Yellow
write-host “”

$SCPURL = “https://” + $base + $SCPExtend

[array]$SCPCurrent = Get-ClientAccessServer

Foreach ($value in $SCPCurrent) {
    Write-host “Looking at Server: ” $value.name
    Write-host “Current SCP value: ” $value.AutoDiscoverServiceInternalUri.absoluteuri
    Write-host “New SCP Value:     ” $SCPURL
    [string]$set = Read-host $ConfirmPrompt
    write-host “”
    if ($set -eq “Y”)    {
         Set-ClientAccessServer -id $value.identity -AutoDiscoverServiceInternalUri $SCPURL
    }    else {
        write-host “Autodiscover Service Connection Point internal value NOT changed” -foregroundcolor $NoChangeForeground -backgroundcolor $NoChangeBackground
    }
}

# =============================================
# Build the EWS URL and set the internal Value

Write-host “Setting Exchange Web Services Virtual Directories” -foregroundcolor Yellow
write-host “”

$EWSURL = “https://” + $base + $EWSExtend

[array]$EWSCurrent = Get-WebServicesVirtualDirectory

Foreach ($value in $EWSCurrent) {
    Write-host “Looking at Server: ” $value.server
    Write-host “Current Internal Value: ” $value.internalURL
    Write-host “New Internal Value:     ” $EWSUrl
    [string]$set = Read-host $ConfirmPrompt
    write-host “”

    if ($set -eq “Y”)    {
        Set-WebServicesVirtualDirectory -id $value.identity -InternalURL $EWSURL
     } else {
        write-host “Exchange Web Services Virtual Directory internal value NOT changed” -foregroundcolor $NoChangeForeground -backgroundcolor $NoChangeBackground
     }

    Write-host “Looking at Server: ” $value.server
    Write-host “Current External Value: ” $value.externalURL
    Write-host “New External Value:     ” $EWSUrl
    [string]$set = Read-host $ConfirmPrompt
    write-host “”

    if ($set -eq “Y”)    {
        Set-WebServicesVirtualDirectory -id $value.identity -ExternalURL $EWSURL
    } else {
        write-host “Exchange Web Services Virtual Directory external value NOT changed” -foregroundcolor $NoChangeForeground -backgroundcolor $NoChangeBackground
    }
}

# =============================================
# Build the PowerShell URL and set the internal Value

Write-host “Setting UM Virtual Directories” -foregroundcolor Yellow
write-host “”

$PShURL = “http://” + $base + $PShExtend

[array]$PShCurrent = Get-PowerShellVirtualDirectory

foreach ($value in $PShCurrent) {
    Write-host “Looking at Server: ” $value.server
    Write-host “Current Internal Value: ” $value.internalURL
    Write-host “New Internal Value:     ” $PShUrl
    [string]$set = Read-host $ConfirmPrompt
    write-host “”

    if ($set -eq “Y”) {
        Set-PowerShellVirtualDirectory -id $value.identity -InternalURL $PShURL
    } else {
        write-host “PowerShell Virtual Directory internal value NOT changed” -foregroundcolor $NoChangeForeground -backgroundcolor $NoChangeBackground
    }

    Write-host “Looking at Server: ” $value.server
    Write-host “Current External Value: ” $value.externalURL
    Write-host “New External Value:     ” $PShUrl
    [string]$set = Read-host $ConfirmPrompt
    write-host “”

    if ($set -eq “Y”) {
        Set-PowerShellVirtualDirectory -id $value.identity -ExternalURL $PShURL
    } else {
        write-host “PowerShell Virtual Directory external value NOT changed” -foregroundcolor $NoChangeForeground -backgroundcolor $NoChangeBackground
    }
}

# =============================================
# Build the ECP URL and set the internal Value

Write-host “Setting ECP Virtual Directories” -foregroundcolor Yellow
write-host “”

$ECPURL = “https://” + $base + $ECPExtend

[array]$ECPCurrent = Get-ECPVirtualDirectory

foreach ($value in $ECPCurrent) {
    Write-host “Looking at Server: ” $value.server
    Write-host “Current Internal Value: ” $value.internalURL
    Write-host “New Internal Value:     ” $ECPUrl
    [string]$set = Read-host $ConfirmPrompt
    write-host “”

    if ($set -eq “Y”) {
        Set-ECPVirtualDirectory -id $value.identity -InternalURL $ECPURL
    } else {
        write-host “ECP Virtual Directory internal value NOT changed” -foregroundcolor $NoChangeForeground -backgroundcolor $NoChangeBackground
    }

    Write-host “Looking at Server: ” $value.server
    Write-host “Current External Value: ” $value.externalURL
    Write-host “New External Value:     ” $ECPUrl
    [string]$set = Read-host $ConfirmPrompt
    write-host “”

    if ($set -eq “Y”) {
        Set-ECPVirtualDirectory -id $value.identity -ExternalURL $ECPURL
    } else {
        write-host “ECP Virtual Directory external value NOT changed” -foregroundcolor $NoChangeForeground -backgroundcolor $NoChangeBackground
    }
}

# =============================================
# Build the OWA URL and set the internal Value

Write-host “Setting OWA Virtual Directories” -foregroundcolor Yellow
write-host “”

$OWAURL = “https://” + $base + $OWAExtend

[array]$OWACurrent = Get-OWAVirtualDirectory

foreach ($value in $OWACurrent) {
    Write-host “Looking at Server: ” $value.server
    Write-host “Current Internal Value: ” $value.internalURL
    Write-host “New Internal Value:     ” $OWAUrl
    [string]$set = Read-host $ConfirmPrompt
    write-host “”

    if ($set -eq “Y”) {
        Set-OWAVirtualDirectory -id $value.identity -InternalURL $OWAURL
    } else {
        write-host “OWA Virtual Directory internal value NOT changed” -foregroundcolor $NoChangeForeground -backgroundcolor $NoChangeBackground
    }

    Write-host “Looking at Server: ” $value.server
    Write-host “Current External Value: ” $value.externalURL
    Write-host “New External Value:     ” $OWAUrl
    [string]$set = Read-host $ConfirmPrompt
    write-host “”

    if ($set -eq “Y”) {
        Set-OWAVirtualDirectory -id $value.identity -ExternalURL $OWAURL
    } else {
        write-host “OWA Virtual Directory external value NOT changed” -foregroundcolor $NoChangeForeground -backgroundcolor $NoChangeBackground
    }
}

# =============================================
# Build the EAS URL and set the internal Value

Write-host “Setting EAS Virtual Directories” -foregroundcolor Yellow
write-host “”

$EASURL = “https://” + $base + $EASExtend

[array]$EASCurrent = Get-ActiveSyncVirtualDirectory

foreach ($value in $EASCurrent) {
    Write-host “Looking at Server: ” $value.server
    Write-host “Current Internal Value: ” $value.internalURL
    Write-host “New Internal Value:     ” $EASUrl
    [string]$set = Read-host $ConfirmPrompt
    write-host “”

    if ($set -eq “Y”) {
        Set-ActiveSyncVirtualDirectory -id $value.identity -InternalURL $EASURL
    } else {
        write-host “EAS Virtual Directory internal value NOT changed” -foregroundcolor $NoChangeForeground -backgroundcolor $NoChangeBackground
    }

    Write-host “Looking at Server: ” $value.server
    Write-host “Current External Value: ” $value.externalURL
    Write-host “New External Value:     ” $EASUrl
    [string]$set = Read-host $ConfirmPrompt
    write-host “”

    if ($set -eq “Y”) {
        Set-ActiveSyncVirtualDirectory -id $value.identity -ExternalURL $EASURL
    } else {
        write-host “EAS Virtual Directory external value NOT changed” -foregroundcolor $NoChangeForeground -backgroundcolor $NoChangeBackground
    }
}
Stop-Transcript

9 Comments

  • By Pritesh Patel, October 27, 2010 @ 12:48 pm

    I’ve used this script – its great! Thanks for your efforts Nathan.

  • By Andre Guerreiro, August 8, 2011 @ 2:36 pm

    Hello.
    This looks kewl, but how would I go about running this script?
    TIA,
    Andre’

  • By Nathan Winters, September 6, 2011 @ 8:47 pm

    Hi,
    You would copy it into a text editor and save it with a .PS1 extension.
    Then run it from PowerShell.
    Cheers
    Nathan

  • By James, November 4, 2011 @ 10:11 am

    What parts do we need to edit. I have changed the url to the required site mail.mysite.com but it doesnt add any url internally and therefore errors.

  • By Nathan Winters, March 3, 2012 @ 9:29 am

    Sorry it’s been ages since I check this….. Hope you got it working in the end.
    Cheers
    Nathan

  • By Carol Ostos, March 16, 2012 @ 5:06 am

    How about if you have 2 domains (AMERICA and EUROPE) both using the same smtp address, domainname.com and there is already an autodiscovery.domainname.com in the external DNS in use by iphone users in AMERICA, what do you think it would be easier to allow new Exchange 2010 CAS servers in EUROPE to use autodiscover.domainname.com with european iphone users. Hope this makes sense. Thanks!

  • By Nathan Winters, March 16, 2012 @ 8:10 pm

    Hi Carol,
    This could be a rather large discussion. So I suggest you mail me or post on the Minasi forum (www.minasi.com/forum) and then we can discuss.
    Cheers
    Nathan

  • By Ken Greber, May 4, 2012 @ 8:42 am

    What an absolutely awesome script did the job in about 30 seconds. Easy mode ;P

Other Links to this Post

  1. Tweets that mention Script to set InternalURL and ExternalURL for all Exchange 2010 Virtual Directories | nathanwinters.co.uk -- Topsy.com — May 30, 2010 @ 2:40 pm

RSS feed for comments on this post. TrackBack URI

Leave a comment

WordPress Themes

Get Adobe Flash player