The Exchange 2007 Wiki

set-allvdirs

Description 

This script will allow you to configure all of the Exchange virtual directories that are related to Autodiscover to a single domain name like mail.company.com.  I will also set the SCP for you. 

Usage

Copy this script into notepad and save it in the $PShome location with the name set-allvdirs.ps1. Then from PowerShell run set-allvdirs.ps1. The script will prompt you for any information it needs and will prompt you before making any changes.

Version History:

10/1/08: Added variables in place of hard coded text strings. Added transcript commands so that we maintain a record of the changes. Added better handling of the OAB URIs to accommodate SSL when using a trusted cert, and straight HTTP when using an internal cert. Corrected some minor case issues with URI paths.
04.12: Modified script to set the OAB virtual directory to http instead of https
04.12: Corrected script to better handle multiple CAS servers

Sample Script

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

Start-Transcript

# Variables

[string]$UMExtend = "/UnifiedMessaging/Service.asmx"
[string]$OABExtend = "/OAB"
[string]$SCPExtend = "/Autodiscover/Autodiscover.xml"
[string]$EWSExtend = "/EWS/Exchange.asmx"
[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 Autodiscover provided services to the name you provide."
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 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://"
}    else    {
    [string]$OABprefix = "https://"
}

# =======================================================
# 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 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
    } 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
    } else {
        write-host "OAB Virtual Directory external value NOT changed" -foregroundcolor $NoChangeForeground -backgroundcolor $NoChangeBackground
    }
}

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

Write-host "Setting UM Virtual Directories" -foregroundcolor Yellow
write-host ""

$UMURL = "https://" + $base + $UMExtend

[array]$UMCurrent = Get-UMVirtualDirectory

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

    if ($set -eq "Y") {
        Set-UMVirtualDirectory -id $value.identity -InternalURL $UMURL
    } else {
        write-host "UM 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:     " $UMUrl
    [string]$set = Read-host $ConfirmPrompt
    write-host ""

    if ($set -eq "Y") {
        Set-UMVirtualDirectory -id $value.identity -ExternalURL $UMURL
    } else {
        write-host "UM Virtual Directory external value NOT changed" -foregroundcolor $NoChangeForeground -backgroundcolor $NoChangeBackground
    }
}
Stop-Transcript

Comments

From Apoc - 1/3/08 11:41 PM

Hi,

with Exchange 2007 SP1 I do get an Access is denied error when setting the Setting Exchange Web Services Virtual Directories and all following entries.

Is there a security issue with SP1?


Cheers,

Thomas

From jimclarkcrs - 8/18/07 1:25 PM

I had the same Outlook client errors. I worked with Dell support (where I got Exchange from) and they led me thru a number of things but I think by going into Add/Remove programs - Remove Exchange 2007 - "Client Access Role" and then adding it back - Worked!

From Simmo93tt - 8/8/07 9:43 PM

Hi,

I am having the exact same error on my outlook clients: 

 

Task "microsoft exchange" reported error (0X80190193) : The operation failed

 

Has anyone found more information on this error or a fix?

 

Cheers,

 Simon.

From boe - 5/11/07 12:05 PM

Matt - I really appreciate your help on this - as far as I can tell everything is working however both internal clients and external clients get the following error in outlook upon send/receive - I don't see anything in the event viewer

Task "microsoft exchange" reported error (0X80190193) : The operation failed 

From matbyrd - 5/10/07 11:27 AM

Hi Boe,

It all depends on if your client can or cannot access the domain.  If your client can talk to a Domain controller directly then you can connect to AD and get the SCP record from AD.  You can set the SCP record to any value that you like; as long as that FQDN can be resolved by outlook. i.e. exchange.mydomain.com.

Also that value will work on any SMTP addresses that you have defined for your users.  Again NOTE the SCP ONLY applies to clients that can Directly Access AD.  If your client is not on the corporate network or is not domain joined then Outlook is hard coded to look for autodiscover.company.com and company.com ... where company.com is the portion of your SMTP address after the @ sign.

So if your primary SMTP address is thisisme@mydomain.com and you are not on the corporate network to pick up the SCP then Outlook 2007 must be able to find either https://autodiscover.mydomain.com or https://mydomain.com 

 -Matt

From boe - 5/5/07 9:19 PM

Hello,

I just ran this script - looked like it did everything OK I filled in the value exchange.mydomain.com instead of mail.mydomain.com - however when I checked my olkdisc.log from Outlook 2007, it shows it tried to

Thread Tick Count Date/Time Description
2088 40453203 05/05/07 22:24:26 Autodiscover to https://mydomain.com/autodiscover/autodiscover.xml starting
2088 40454328 05/05/07 22:24:27 Autodiscover to https://mydomain.com/autodiscover/autodiscover.xml FAILED (0x800C8203)

 

previously it was going to https://exchange.mydomain.com/autodiscover/autodiscover

 I'd really like my outlook client to be searching for exchange.mydomain.com/autodiscover but I have no idea how to switch it back.

 

I'd love to add a second mail domain to my server - not really sure any of the autodiscover process for a second mail domain - currently all I have set up is send or receive for the second domain however it is looking for a another autodiscover site that doesn't exist and even if I create that second site, (not sure any of the process for it)   I'm concerned if I run this script without fully understanding it, I might accidentally disable the first doman's autodiscover.

 

 

 

 

Thanks

Site

Changes
Index
Search

 

User

 

Log In
Register

 
 

Last Modified 10/1/08 6:39 PM