<# .DESCRIPTION This script will perform an update of the Offline Address Book Service, but will configure logging levels to aid in troubleshooting. These logs will then be collated into a single log file for viewing. .PARAMETER oAddressBook -oAddressBook "Address Book Name" -fHTML "Path and Filename for HTML Report" .EXAMPLE .\updateOABandLog.ps1 -oAddressBook "" -fHTML .Copyright_Author (c) 2012 www.telnetport25.com Author: Andy Grogan .Version v1.0 - First Release #> param( [parameter(Mandatory=$true,ValueFromPipeline=$false,HelpMessage="Name of the Offline Address Book that you wish to update")]$oAddressBook, [parameter(Mandatory=$true,ValueFromPipeline=$false,HelpMessage="Path and Filename to report file")]$fHTML ) function checkExchangeSN { if (! (Get-PSSnapin Microsoft.Exchange.Management.PowerShell.E2010 -ErrorAction:SilentlyContinue) ) { Add-PSSnapin Microsoft.Exchange.Management.PowerShell.E2010 -ErrorAction:Stop } } New-Item -ItemType file $fHTML -Force | Out-Null $ComputerName = $env:COMPUTERNAME Write-Host "Execution Computer Name is: " $ComputerName -ForegroundColor White function writeHeader{ param($fileName) Add-Content $fileName "" Add-Content $fileName "" Add-Content $fileName "" Add-Content $fileName 'OAB Events Report' Add-content $fileName '" Add-Content $fileName "" Add-Content $fileName "" Add-content $fileName "" Add-content $fileName "" Add-content $fileName "" Add-content $fileName "" Add-content $fileName "
" Add-content $fileName "Offline Address Book Processing Log - Executed on: $ComputerName" Add-content $fileName "
" } function WriteFooter(){ Param($fileName) Add-Content $fileName "" Add-Content $fileName "" } function script_Logging($logEntry,$Colour){ Write-Host $logEntry -ForegroundColor $Colour } function get_OABServer{ $oabGenSrv = Get-OfflineAddressBook $oAddressBook | Select -ExpandProperty Server return $oabGenSrv } function set_Logging($switch){ script_Logging "Getting OAB Generation Server" "Green" $GenerationServer = get_OABServer script_Logging "OAB Generation Server is: $GenerationServer" "Yellow" $URIString = "http://" + $GenerationServer + "/Powershell" script_Logging $URIString "Green" script_Logging "Setting up new PS Session to remote host" "Green" $Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionURI $URIString script_Logging "Getting Mode" "Green" if($switch.ToLower() -eq 'enable'){ script_Logging "Mode Set to Enable" "Green" Invoke-Command -Session $Session { Set-EventLogLevel -Identity "MSExchangeSA\OAL Generator" -Level Expert -Confirm:$False } script_Logging "Exiting Remote PS Session" "Cyan" Exit-PSSession }else{ script_Logging "Mode Set to Disable" "Green" Invoke-Command -Session $Session { Set-EventLogLevel -Identity "MSExchangeSA\OAL Generator" -Level Lowest -Confirm:$False } script_Logging "Exiting Remote PS Session" "Cyan" Exit-PSSession } } function update_OAB{ Param($fileName) $PerformUpdate = Update-OfflineAddressBook -Identity $oAddressBook script_Logging "Sleeping for 60 Seconds - ZZZZZZzzzzzzzzzz" "Green" Sleep 60 $GenerationServer = get_OABServer script_Logging "Getting Event Logs from System Attendant on OAB Server" "Green" $oabEVENTS = Get-EventLog -ComputerName $GenerationServer -LogName "Application" -Source "MSExchangeSA" | where {$_.Category -eq 'OAL Generator'} Add-Content $fileName "

OAB Generation Event Logs from OAB Generation Server: $GenerationServer

" Add-Content $fileName "" Add-Content $fileName "" Add-Content $fileName "" Add-Content $fileName "" Add-Content $fileName "" Add-Content $fileName "" Add-Content $fileName "" Add-Content $fileName "" Add-Content $fileName "" foreach($evt in $oabEVENTS){ $evtID = $evt.EventID $evtTime = $evt.TimeGenerated $evtMachine = $evt.MachineName $evtCat = $evt.Category $evtType = $evt.EntryType $evtMessage = $evt.Message if($evtType -eq 'Error'){ Add-Content $fileName "" Add-Content $fileName "" Add-Content $fileName "" Add-Content $fileName "" Add-Content $fileName "" Add-Content $fileName "" Add-Content $fileName "" Add-Content $fileName "" }elseif($evtType -eq 'Warning'){ Add-Content $fileName "" Add-Content $fileName "" Add-Content $fileName "" Add-Content $fileName "" Add-Content $fileName "" Add-Content $fileName "" Add-Content $fileName "" Add-Content $fileName "" }else{ Add-Content $fileName "" Add-Content $fileName "" Add-Content $fileName "" Add-Content $fileName "" Add-Content $fileName "" Add-Content $fileName "" Add-Content $fileName "" Add-Content $fileName "" } } Add-Content $fileName "
Event IDTime GeneratedMachine NameCategoryEntry TypeMessage
$evtID$evtTime$evtMachine$evtCat$evtType$evtMessage
$evtID$evtTime$evtMachine$evtCat$evtType$evtMessage
$evtID$evtTime$evtMachine$evtCat$evtType$evtMessage
" } writeHeader $fHTML checkExchangeSN set_logging "enable" "Green" update_OAB $fHTML set_logging "disable" "Green" writeFooter $fHTML script_Logging "Script Completed" "Yellow" Invoke-Item $fHTML