Posts tagged: 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
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!



Set Outlook Web App (OWA) Logon Format with PowerShell script

I’ve been working with 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.

Below is a script I put together to set the logon format for OWA. Basically it prompts the user about the various types of format available and then goes and builds the relevant commands to configure any Client Access servers in the environment. It should work against Exchange 2007 and 2010 although I’ve only tested Exchange 2010.


Write-host "This script will let you set the logon format for OWA virtual directories on Exchange 2010."
Write-host ""

#Set Variables
[string]$ConfirmPrompt = "Set this Value? (Y/N)"
[string]$WarningForeground = "white"
[string]$WarningBackground = "red"

#Build Array of OWA virtual directories and then run through for the user

[array]$OWAVDir = Get-OwaVirtualDirectory

#Prompt user about how they want login to occur and then get selection
Write-host "How do you want users to log into OWA?"

[string]$type = Read-host "You have three options, EmailAddress (UPN), Domain\username or username. Please enter one of (Email / Domain / Username)"

Write-host ""

#Create function for calling later which will do the setting of properties

function ConfigureVirtualDirectory
#Get the current AD domain FQDN for use as the default domain if Username format is chosen.

$ADdomain = [System.DirectoryServices.ActiveDirectory.Domain]::GetCurrentDomain()

    if ($type -eq "Email")    {
        Write-host "You have opted to use the email address. Please make sure users UPN in active directory matches their email address" -foregroundcolor $WarningForeground -backgroundcolor $WarningBackground
        Foreach ($value in $OWAVDir) {
            Set-OwaVirtualDirectory -Identity $value -LogonFormat PrincipalName }
    if ($type -eq "Domain")    {
        Foreach ($value in $OWAVDir) {
            Set-OwaVirtualDirectory -Identity $value -LogonFormat FullDomain }
    if ($type -eq "Username")    {
        Foreach ($value in $OWAVDir) {
            Set-OwaVirtualDirectory -Identity $value -LogonFormat UserName -DefaultDomain $ADdomain }

#Tell user what is about to happen for each server and then give choice to execute

Write-host “Looking at Server: ” $OWAVDir[0].server
    Write-host “Current Logon Format: ” $OWAVDir[0].logonformat
    Write-host “New Logon Format Type:     ” $Type
   [string]$set = Read-host $ConfirmPrompt
    Write-host “”

    if ($set -eq "Y")    {
    }    else    {
        Write-host "Nothing has been changed, script quit" -foregroundcolor $WarningForeground -backgroundcolor $WarningBackground


WordPress Themes

Get Adobe Flash player