OAB Corruption

MBX sometime failed to update their OAB and even if you try to move them to another MBX the problem persist.
When that happen this Event Id is written in the Event Log of the MBX and the OAB doesn’t update anymore

Source : MSExchangeSA Event ID:9408 Content : OABGen failed to load the OAB version 4 manifest file ‘\MBXExchangeOABXXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXXoab.xml’. This may indicate data tampering or disk problems. Restore files in this folder from the recent backup or clean up folder content and force a full OAB generation.
– Name of the OAB

To resolve this issue you have 2 way as told by the event, this script take option 2 since I don’t backup file that can be recreated by a service.
It may work on Exchange 2007, but I have only test it on Exchange 2010. I run it as a schedule task.

Look like my code formater doesn’t like >= and <= so just change &gt;= and &lt;= in $EventList

	[string] $Server,
	[switch] $Confirm,
	[string] $OutputFile = ".Corrupted-OAB.txt",
	[array] $Email,
	[switch] $Help

$versionText ="
Goal: Erase OAB file that are corrupt on MBX server to force a regeneration
Author: Simon Poirier
Version 1.0

Version History
Version 1.0 - Creation of the script by Simon Poirier

You can specify MBX server name to run the script only on that one

Parameter Explanation and Usage
-Server : MBX Server Name
-OutFile : Set the path for the report file
-Email : List of email to which the report will be send, separated by comma
-Help : Show the Usage of the script
-Confirm : Need to be use for the script to execute.


#Declare Variables
$EventList = $NULL
$Item = $NULL
$Temp = $NULL
$DateBefore = $NULL
$DateAfter = $NULL
$OABPath = $NULL
$oabfile = $NULL
$lastoabfile = $NULL
$tc = [System.Management.ManagementDateTimeconverter]
$Start = $NULL
$End = $NULL
$Serverlist = $NULL
$serverName = $NULL
$NumberOfRepair = 0
$OABName = $NULL
$temp = Get-Date
$temp = $temp.ToShortDateString()
$msg = new-object Net.Mail.MailMessage

# Variable to change
$DateBefore = $temp +" 11:59 AM" ### End time of generation for OAB
$DateAfter = $temp +" 5:00 AM" ### Start time of generation for OAB
$smtpServer = "smtp.domain.com" ### SMTP server to use to send the report
$msg.From = "EX_NoReply@Domain.com" ### Mail from of the report
$msg.Subject = "Exchange - Corrupted OAB Report" ### Subject of the report

# To show Help
if($Help -eq $True){
Write-Host $VersionText

# Confirm Caller
# To show the details when using the -Confirm switch.
if($Confirm -ne $True){
Write-Warning "The script will not execute unless you can confirm you know what it is doing!
Please run the script with -Help to see what it is doing and how-to use it."

# Create the report file and clear
Out-File $OutputFile -Encoding ascii
Add-Content $OutputFile "+-------------------------------------------------------------------------------------+"
Add-Content $OutputFile " "
Add-Content $OutputFile " Exchange Corrupted OAB"
Add-Content $OutputFile " "
Add-Content $OutputFile "+-------------------------------------------------------------------------------------+"
$Time = Get-Date
Add-Content $OutputFile "Script start at : $Time"
Add-Content $OutputFile "`n "

# Getting the time to scan for those event
$Start =$tc::ToDmtfDateTime((Get-Date $DateAfter))
$End =$tc::ToDmtfDateTime((Get-Date $DateBefore))

# Getting list of server if -Server is not used
if($Server -eq ""){
$Serverlist = Get-MailboxServer| Sort Name | Select Name
$ServerList = $server

# Getting Event list
ForEach($item in $Serverlist){
if($Server -eq ""){
$Servername = $item.name
$Servername = $Server

$EventList = Get-WMIObject Win32_NTLogEvent -ComputerName $servername -Filter "LogFile='Application' AND EventCode=9408 AND TimeWritten>='$Start' AND TimeWritten<='$End'" 

# Delete all folder that have problem
	if($EventList -ne $NULL){
		Foreach($Item in $Eventlist){
			$temp = $NULL
			$temp = $Item.InsertionStrings
			$OABfile = $temp[0]
			$OABName = $OABfile.Split("")
			$OABName = $OABName[4]
			if($oabfile -ne $lastoabfile){
				$oabpath = $oabfile.TrimEnd("aob.xml")
				$OABName = Get-OfflineAddressBook $OABName | select Name
				$OABName = $OABName.Name
				Write-host "Remove-Item $oabPath -force -recurse for domain $OABName"
				Add-Content $OutputFile "Remove-Item $oabPath -force -recurse  (Domain : $OABName )`n" 
				Remove-Item $oabPath -force -recurse
				$NumberOfRepair += 1
			$lastoabfile = $oabfile

#Add a stamp time at the end of the script to the file
Add-Content $OutputFile  "`n`n`n "
$Time = Get-Date
Add-Content $OutputFile  "`nScript end at : $Time"
Add-Content $OutputFile  "`n "

# Send Email of the result
if(($Email -ne "") -and ($NumberOfRepair -gt 0) ){
	$msg = new-object Net.Mail.MailMessage
	$smtp = new-object Net.Mail.SmtpClient($smtpServer)
	$temp = $Email.split(" ")
	foreach($Item in $temp){
	$msg.Body = [string]::join([environment]::newline, (Get-Content $OutputFile))
	Write-Host "Email Send"

3 thoughts on “OAB Corruption”

  1. When I try to run this script, I get en error:

    The string starting at C:pathtoscript.ps1:140 char:23
    + Write-Host “Email Send <<<< "
    is missing the terminator: ".
    At C:pathtoscript.ps1:141 char:2
    + } <<<<


    1. I think it’s missing a trailing ” on the line

      $EventList = Get-WMIObject Win32_NTLogEvent -ComputerName $servername -Filter ”


      1. I didn’t review the script in the post, but effectively it seem to be there
        line should be

        $EventList = Get-WMIObject Win32_NTLogEvent -ComputerName $ServerName -Filter “LogFile=’Application’ AND EventCode=9408 AND TimeWritten>=’$Start’ AND TimeWritten< =’$End’” It’s look like the code formater isn’t appreciating >= and <= in the line.

Leave a Reply

Your email address will not be published. Required fields are marked *