Category: PowerShell

PowerShell scripting a Parsing error – TerminatorExpectedAtEndOfString

I’ve been diving into PowerShell recently as you can see from my recent blog posts on setting Exchange 2010 virtual directory settings and on redirecting the OWA URL from http to https.

The inspiration has been my project to write up an article detailing a simple Exchange install for a single server Exchange 2010 environment. The aim was to provide a simple set of steps for small IT shops to follow, which lead my to try and automate a few things.

Whilst doing writing a script with user interaction to set the logon format for OWA I kept getting the below error:

[PS] C:\Users\administrator.GAOTS\Desktop>.\SetOWALogonFormat.ps1
The string starting:
At C:\Users\administrator.GAOTS\Desktop\SetOWALogonFormat.ps1:56 char:55
+         Write-host "Nothing has been changed, script quit <<<< " -foregroundcolor $WarningForeground -backgroundcolor
$WarningBackground
is missing the terminator: ".
At C:\Users\administrator.GAOTS\Desktop\SetOWALogonFormat.ps1:61 char:18
+ iisreset /noforce <<<<
    + CategoryInfo          : ParserError: ( -foregroundcol…sreset /noforce:String) [], ParseException
    + FullyQualifiedErrorId : TerminatorExpectedAtEndOfString

Well it turned out that a couple of things were the problem.

Firstly I checked for any “ that were in the wrong place (or in my case additional ones!)

Then I did a find and replace on all “ in the script which seemed to make the parser happy! I guess maybe this was the age old copy and paste problem with smart quotes from word??

Hope that helps a little!

Cheers

Nathan

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

WordPress Themes

Get Adobe Flash player