Exchange 2007 / Outlook 2003 / Blackberry & OoO

I saw Andy posted this (http://telnetport25.wordpress.com/2008/03/16/quick-ish-tip-exchange-2007-setting-oof-for-users-via-powershell-2/) today and wanted to share my script.

It uses the same dll from Glen(EWSOofUtil.dll) to open the specified users mailbox and Enable/Disable a users Out Off Office Setting. This in theory fixes an Issue with Exchange 2007 and Outlook 2003/Blackberry Enterprise Server

The script also checks to see if a user has a legacy account set as Associated External. If it has it removes it and writes to a log.  It does this as the “Super Account” I was using could open the OoO if this was set!

EWSOofUtil.dll is provided by Glen Scales (http://gsexdev.blogspot.com)

The script can also be used in a pipeline.

##########################################################################################
Param ($Username)
##########################################################################################
$AppName = “Fix-OoO.ps1”
$AppVer  = “v1.1 [6 March 2008]”
#
#v1.0 2 March 2008     : A script it born
#v1.1 6 March 2008     : Updated to remove legacy account and added more logging
#
# This script uses EWSOofUtil.dll to open the specified users mailbox and Enable/Disable
# a users Out Off Office Setting.  This in theory fixes an Issue with Exchange 2007
# and Outlook 2003/Blackberry Enterprise Server
#
# The script also checks to see if a user has a legacy account set as Associated External
# If it has it removes it and writes to a log
#
#Written By Paul Flaherty                  
#blogs.flaphead.com                        
#
#Syntax
#Fix-OoO.ps1
#
#Can be in the pipeline
#get-mailbox -database M03VASG03-M03VASG03-DB01-M03VA  -resultsize unlimited | where {$_.islinked -eq $False} | foreach-object {c:psFix-OoO.ps1 $_.Name}
#
#Other samples
#
#$Server = “M01VA”
#get-mailbox -database $ServerSG01-$ServerSG01-DB01-$Server  -resultsize unlimited | where {$_.islinked -eq $False} | foreach-object {c:psFix-OoO.ps1 $_.Name}
#get-mailbox -database $ServerSG02-$ServerSG02-DB01-$Server  -resultsize unlimited | where {$_.islinked -eq $False} | foreach-object {c:psFix-OoO.ps1 $_.Name}
#get-mailbox -database $ServerSG03-$ServerSG03-DB01-$Server  -resultsize unlimited | where {$_.islinked -eq $False} | foreach-object {c:psFix-OoO.ps1 $_.Name}
#get-mailbox -database $ServerSG04-$ServerSG04-DB01-$Server  -resultsize unlimited | where {$_.islinked -eq $False} | foreach-object {c:psFix-OoO.ps1 $_.Name}
#get-mailbox -database $ServerSG05-$ServerSG05-DB01-$Server  -resultsize unlimited | where {$_.islinked -eq $False} | foreach-object {c:psFix-OoO.ps1 $_.Name}
#get-mailbox -database $ServerSG06-$ServerSG06-DB01-$Server  -resultsize unlimited | where {$_.islinked -eq $False} | foreach-object {c:psFix-OoO.ps1 $_.Name}
#get-mailbox -database $ServerSG07-$ServerSG07-DB01-$Server  -resultsize unlimited | where {$_.islinked -eq $False} | foreach-object {c:psFix-OoO.ps1 $_.Name}
#get-mailbox -database $ServerSG08-$ServerSG08-DB01-$Server  -resultsize unlimited | where {$_.islinked -eq $False} | foreach-object {c:psFix-OoO.ps1 $_.Name}
#
##########################################################################################

IF ($Username -eq $Null)
{
    Write-Host “Enter UserName: ” -NoNewLine
    $Username = Read-Host
}

IF ($username -ne $null)
{
    #Check Permissions
    $xPerms = get-mailboxPermission -Identity $Username -user corebus1$Username
    ForEach ($xPerm in $xPerms)
    {
        $xAccess = $xPerm.AccessRights | Out-String
        $xAccess = $xAccess.Trim()
        If ($xAccess.Contains(“ExternalAccount”))
        {
            write-host $xPerm.User -NoNewLine -foregroundcolor Yellow
            write-host ” : ” -NoNewLine
            write-host $xPerm.AccessRights

            Add-content c:tempOoO-Fail-AccessRights.txt “$UserName,corebus1$Username,$xAccess “
            Remove-MailboxPermission -Identity $Username -user $xPerm.User -AccessRight ExternalAccount -Confirm:$False

        }
    }

    $Username += “@flaphead.local”
    Write-host $Username -foregroundcolor Green
    $MsxServer =
https://cas01.flaphead.local/EWS/Exchange.asmx

    [Reflection.Assembly]::LoadFile(“c:psEWSOofUtil.dll”)
    $oofutil = new-object EWSOofUtil.OofUtil
    $oofutil.getoof($Username ,””,””,””,$MsxServer)

    $xOoOInternal = $oofutil.InternalMessage
    $xOoOExternal = $oofutil.ExternalMessage

    $xOoOStatus = $oofutil.OofStatus

    IF ($xOoOStatus.Length -eq 0) {Add-content c:tempOoO-Fail.txt $UserName}

    IF ($xOoOStatus.Length -gt 0)
    {

        Write-Host “OoO Status: $xOoOStatus”
        Add-content c:tempOoO-Success.txt “$UserName,$xOoOStatus”

        If ($xOoOStatus -eq “Enabled”)
        {
            Write-Host $xOoOInternal
            $oofutil.setoof($Username ,”Disabled”,””,””,””,””,””,$MsxServer)
            $oofutil.setoof($Username ,”Enabled”,””,””,””,””,””,$MsxServer)
        }
        ELSE
        {
            $oofutil.setoof($Username ,”Enabled”,””,””,””,””,””,$MsxServer)
            $oofutil.setoof($Username ,”Disabled”,””,””,””,””,””,$MsxServer)
        }
    }
}
 &nb
sp;  ELSE
{
    Write-Host “No Username specified”
}

##########################################################################################
#End
##########################################################################################

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

%d bloggers like this: