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 <primary smtp address> # #Can be in the pipeline #get-mailbox -database M03VA\SG03-M03VA\SG03-DB01-M03VA -resultsize unlimited | where {$_.islinked -eq $False} | foreach-object {c:\ps\Fix-OoO.ps1 $_.Name} # #Other samples # #$Server = "M01VA" #get-mailbox -database $Server\SG01-$Server\SG01-DB01-$Server -resultsize unlimited | where {$_.islinked -eq $False} | foreach-object {c:\ps\Fix-OoO.ps1 $_.Name} #get-mailbox -database $Server\SG02-$Server\SG02-DB01-$Server -resultsize unlimited | where {$_.islinked -eq $False} | foreach-object {c:\ps\Fix-OoO.ps1 $_.Name} #get-mailbox -database $Server\SG03-$Server\SG03-DB01-$Server -resultsize unlimited | where {$_.islinked -eq $False} | foreach-object {c:\ps\Fix-OoO.ps1 $_.Name} #get-mailbox -database $Server\SG04-$Server\SG04-DB01-$Server -resultsize unlimited | where {$_.islinked -eq $False} | foreach-object {c:\ps\Fix-OoO.ps1 $_.Name} #get-mailbox -database $Server\SG05-$Server\SG05-DB01-$Server -resultsize unlimited | where {$_.islinked -eq $False} | foreach-object {c:\ps\Fix-OoO.ps1 $_.Name} #get-mailbox -database $Server\SG06-$Server\SG06-DB01-$Server -resultsize unlimited | where {$_.islinked -eq $False} | foreach-object {c:\ps\Fix-OoO.ps1 $_.Name} #get-mailbox -database $Server\SG07-$Server\SG07-DB01-$Server -resultsize unlimited | where {$_.islinked -eq $False} | foreach-object {c:\ps\Fix-OoO.ps1 $_.Name} #get-mailbox -database $Server\SG08-$Server\SG08-DB01-$Server -resultsize unlimited | where {$_.islinked -eq $False} | foreach-object {c:\ps\Fix-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:\temp\OoO-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:\ps\EWSOofUtil.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:\temp\OoO-Fail.txt $UserName}
IF ($xOoOStatus.Length -gt 0) {
Write-Host "OoO Status: $xOoOStatus" Add-content c:\temp\OoO-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) } } } ELSE { Write-Host "No Username specified" }
########################################################################################## #End ##########################################################################################
Managing Folders in Outlook 2007 Cross Forest Exchange Impersonation in Exchange 2007 Service Pack 1