Check the oab.xml file age
http://www.corelan.be:8800/index.php/2009/05/22/fixing-exchange-2007-offline-address-book-generation-oalgen-and-distribution-issues/ and he did posted the powershell scripts # # Powershell Script written by Peter Van Eeckhoutte # # Purpose : monitor the oab.xml timestamp # and report timestamp issues via email # # http://www.corelan.be:8800 # # ############ Edit the following fields ################################## $emailFrom = "postmaster@" $emailTo = "" $emailCC = "" $smtpServer = "" $oabpath = "c:\Program Files\Microsoft\Exchange Server\ClientAccess\OAB\b5dbeea9-2302-4d1a-8440-b9384a3e116b" $alerthours=25 ######################################################################### # # Other vars # $subject = "Possible OABGen problem detected on " + $env:ComputerName $body="" # ###################" # # $basetimestamp=[DateTime]::Now.AddHours($alerthours*-1) # # Get timestamp of oab.xml file $oabfile = get-item $oabpath"\oab.xml" write-host "Current oab.xml timestamp : " $oabfile.lastaccesstime write-host "Comparing this timestamp with " $basetimestamp if ($oabfile.lastaccesstime -le $basetimestamp) { write-host "oab.xml file is too old ! There may be an oabgen problem !" $body = "The oab.xml (Offline Address Book) file on " + $env:ComputerName $body += " has a timestamp that is older than " + $alerthours + " hours ago`n`n" $body += "File monitored : " + $oabpath + "\oab.xml`n" $body += "File timestamp : " + $oabfile.lastaccesstime #send email $smtp = new-object Net.Mail.SmtpClient($smtpServer) $smtp.Send($emailFrom, $emailTo, $subject, $body) write-host "Email sent`n" } else { write-host "oab.xml file timestamp is ok" } # # And the Script is work well. However, this scipts only check the guid (c:\Program Files\Microsoft\Exchange Server\ClientAccess\OAB\abcdefgh-djdjdjdj-iiiiiii-zieueie) last modofied date not c:\Program Files\Microsoft\Exchange Server\ClientAccess\OAB\abcdefgh-djdjdjdj-iiiiiii-zieueie\oab.xml) last modified date Here is result when i run this powershell: C:\scripts>Powershell.exe -command "& {C:\scripts\oabcheck.ps1 }" Current oab.xml timestamp : 7/7/2010 9:24:56 AM Comparing this timestamp with 6/7/2010 2:25:44 PM oab.xml file timestamp is ok Actually the timestamp : 7/7/2010 9:24:56 AM is for guid's lat modified date. The exact modified date for oab.xml is 6/7/2010 10.00am. Please advice how to modifed the script.
July 7th, 2010 10:42am

Hi, You need to change the command: $oabfile = get-item $oabpath"\oab.xml" This command just gets the folder 'b5dbeea9-2302-4d1a-8440-b9384a3e116b', not oab.xml. So the timestamp time you get is incorrect. to $oabfile = get-item "c:\Program Files\Microsoft\Exchange Server\ClientAccess\OAB\b5dbeea9-2302-4d1a-8440-b9384a3e116b\oab.xml" Then run the script again. More information: How to check the Last access and Last write of the oab.xml file: [ps] get-itemProperty "c:\Program Files\Microsoft\Exchange Server\ClientAccess\OAB\abcdefgh-djdjdjdj-iiiiiii-zieueie\oab.xml" |fl
Free Windows Admin Tool Kit Click here and download it now
July 8th, 2010 1:15pm

Hi, You need to change the command: $oabfile = get-item $oabpath"\oab.xml" This command just gets the folder 'b5dbeea9-2302-4d1a-8440-b9384a3e116b', not oab.xml. So the timestamp time you get is incorrect. to $oabfile = get-item "c:\Program Files\Microsoft\Exchange Server\ClientAccess\OAB\b5dbeea9-2302-4d1a-8440-b9384a3e116b\oab.xml" Then run the script again. Hi, First of all This line of script is quite right: $oabfile = get-item $oabpath"\oab.xml" You dont need to change it. It really retrieves the oab.xml file. The problem you are facing is due to this property $oabfile.lastaccesstime script is showing you "Last Access Time" of file, not the "Last modified time" of the OAB.xml. To get the last modified time of the OAB you can use "LastWriteTime" property of OAB.xml file. So in your script replace this $oabfile.lastaccesstime with this $oabfile.LastWriteTime everywhere and then you will get proper result. Hope this help you. Regards,Laeeq Qazi|Team Lead(Exchange + Sharepoint + BES + DynamicsCRM) www.HostingController.com
July 8th, 2010 2:33pm

Hi, I tested this script in my lab and it shows the last access time of the folder "b5dbeea9-2302-4d1a-8440-b9384a3e116b"" not the OBA file. Laeeq, Have you tested this script? What's result? Thank you for your reply.
Free Windows Admin Tool Kit Click here and download it now
July 8th, 2010 3:13pm

Hi, I tested this script in my lab and it shows the last access time of the folder "b5dbeea9-2302-4d1a-8440-b9384a3e116b"" not the OBA file. Laeeq, Have you tested this script? What's result? Thank you for your reply. Hi, Gen yes i checked it in my lab first and then posted here. Here is the commands i ran: [PS] C:>$oabpath = "C:\Program Files\Microsoft\Exchange Server\V14\ClientAccess\OAB\0a76b67e-2db2-44f0-bb29-0fd8c36b7fe1" [PS] C:>$oabfile = get-item $oabpath"\oab.xml" [PS] C:>$oabfile Directory: C:\Program Files\Microsoft\Exchange Server\V14\ClientAccess\OAB\0a76b67e-2db2-44f0-bb29-0fd8c36b7fe1 Mode LastWriteTime Length Name ---- ------------- ------ ---- -a--- 7/7/2010 6:35 AM 21449 oab.xml You can see it shows oab.xml under the Name column, and also tells its directory. Regards, Laeeq Qazi|Team Lead(Exchange + Sharepoint + BES + DynamicsCRM) www.HostingController.com
July 8th, 2010 3:24pm

Thank for your help. It is work now but i have another question, how to put send an email as CC:, In this script, they use $emailTo, can i use $emailCC?
Free Windows Admin Tool Kit Click here and download it now
July 9th, 2010 5:23am

Hi, Please refer the following script. ##########Create a message object and initialize############ $msg = new-object System.Net.Mail.MailMessage $emailFrom, $emailTo,$subject, $body ###########add To, CC and BBC recipients ################# $msg.to.Add(user1@domain.com) $msg.cc.Add(user2@domain.com) $msg.bcc.Add (user3@domain.com) $smtp = new-object Net.Mail.SmtpClient($smtpServer) $smtp.Send($msg)
July 9th, 2010 7:58am

I'm edited the scripts (below) but still no CC email being able to send. # # Powershell Script written by Peter Van Eeckhoutte # # Purpose : monitor the oab.xml timestamp # and report timestamp issues via email # # http://www.corelan.be:8800 # # ############Create a message object and initialize####################### $msg = new-object System.Net.Mail.MailMessage $emailFrom,$emailTo,$subject,$body ############ Edit the following fields ################################## $msg.from.Add(postmaster@domain.com) $msg.to.Add(suriya@domain.com) $msg.to.cc.Add(support@domain.com) $smtpServer = "send.domain.com" $smtp = new-object Net.Mail.SmtpClient($smtpserver) $oabpath = "c:\Program Files\Microsoft\Exchange Server\ClientAccess\OAB\b5dbeea9-2302-4d1a-8440-b9384a3e116b" $alerthours=25 ######################################################################### # # Other vars # $subject = "Possible OABGen problem detected on " + $env:ComputerName $body="" # ###################" # # $basetimestamp=[DateTime]::Now.AddHours($alerthours*-1) # # Get timestamp of oab.xml file $oabfile = get-item $oabpath"\oab.xml" write-host "Current oab.xml timestamp : " $oabfile.lastwritetime write-host "Comparing this timestamp with " $basetimestamp if ($oabfile.lastwritetime -le $basetimestamp) { write-host "oab.xml file is too old ! There may be an oabgen problem !" $body = "The oab.xml (Offline Address Book) file on " + $env:ComputerName $body += " has a timestamp that is older than " + $alerthours + " hours ago`n`n" $body += "File monitored : " + $oabpath + "\oab.xml`n" $body += "File timestamp : " + $oabfile.lastwritetime #send email #$smtp = new-object Net.Mail.SmtpClient($smtpServer) $smtp.Send($msg) write-host "Email sent`n" } else { write-host "oab.xml file timestamp is ok" $body = "The oab.xml (Offline Address Book) file on " + $env:ComputerName $body += " has a timestamp as below:`n`n" $body += "File monitored : " + $oabpath + "\oab.xml`n" $body += "File timestamp : " + $oabfile.lastwritetime #send email #$smtp = new-object Net.Mail.SmtpClient($smtpServer) #$smtp.Send($emailFrom, $emailTo, $subject, $body) $smtp.Send($msg) write-host "Email sent`n" } # #
Free Windows Admin Tool Kit Click here and download it now
July 9th, 2010 12:02pm

Hi, Replace the $msg.to.cc.Add(support@domain.com) With $msg.cc.Add(support@domain.com) Then please test it once again.
July 9th, 2010 12:40pm

no luck failed with: C:\scripts>Powershell.exe -command "& {C:\scripts\oabcheck.ps1}" Missing ')' in method call. At C:\scripts\oabcheck.ps1:14 char:15 + $msg.from.Add(p <<<< ostmaster@domain.com) C:\scripts>pause Press any key to continue . . .
Free Windows Admin Tool Kit Click here and download it now
July 12th, 2010 7:16am

no luck failed with: C:\scripts>Powershell.exe -command "& {C:\scripts\oabcheck.ps1}" Missing ')' in method call. At C:\scripts\oabcheck.ps1:14 char:15 + $msg.from.Add(p <<<< ostmaster@domain.com) C:\scripts>pause Press any key to continue . . . Hi, Put email address in double quotes and then check. $msg.from.Add("postmaster@domain.com") $msg.to.Add("suriya@domain.com") $msg.cc.Add("support@domain.com") Besides, I would also suggest you to remove this line $msg.from.Add("postmaster@domain.com") Bcoz you already mentioned From address when you are creating "MailMessage" object. $msg = new-object System.Net.Mail.MailMessage $emailFrom,$emailTo,$subject,$body Regards, Laeeq Qazi|Team Lead(Exchange + Sharepoint + BES + DynamicsCRM) www.HostingController.com
July 12th, 2010 2:21pm

Failed with error: C:\scripts>Powershell.exe -command "& {C:\scripts\oabcheck.ps1}" New-Object : Exception calling ".ctor" with "4" argument(s): "The parameter 'fr om' cannot be an empty string. Parameter name: from" At C:\scripts\oabcheck.ps1:11 char:18 + $msg = new-object <<<< System.Net.Mail.MailMessage $emailFrom,$emailTo,$subj ect,$body You cannot call a method on a null-valued expression. At C:\scripts\oabcheck.ps1:15 char:12 + $msg.to.Add( <<<< "sani@sapura.com.my") You cannot call a method on a null-valued expression. At C:\scripts\oabcheck.ps1:16 char:12 + $msg.cc.Add( <<<< "suriya@sapura.com.my") Current oab.xml timestamp : 12/7/2010 10:05:01 PM Comparing this timestamp with 12/7/2010 9:04:38 AM oab.xml file timestamp is ok Exception calling "Send" with "1" argument(s): "Value cannot be null. Parameter name: message" At C:\scripts\oabcheck.ps1:60 char:15 + $smtp.Send( <<<< $msg) Email sent Updated scripts: # # Powershell Script written by Peter Van Eeckhoutte # # Purpose : monitor the oab.xml timestamp # and report timestamp issues via email # # http://www.corelan.be:8800 # # ############Create a message object and initialize####################### $msg = new-object System.Net.Mail.MailMessage $emailFrom,$emailTo,$subject,$body ############ Edit the following fields ################################## #$msg.from.Add("postmaster@sapura.com.my") $msg.to.Add("sani@sapura.com.my") $msg.cc.Add("suriya@sapura.com.my") #$emailcc = "support.malaysia@sapura.com.my" $smtpServer = "send.sapura.com.my" $smtp = new-object Net.Mail.SmtpClient($smtpserver) $oabpath = "c:\Program Files\Microsoft\Exchange Server\ClientAccess\OAB\b5dbeea9-2302-4d1a-8440-b9384a3e116b" $alerthours=25 ######################################################################### # # Other vars # $subject = "Possible OABGen problem detected on " + $env:ComputerName $body="" # ###################" # # $basetimestamp=[DateTime]::Now.AddHours($alerthours*-1) # # Get timestamp of oab.xml file $oabfile = get-item $oabpath"\oab.xml" write-host "Current oab.xml timestamp : " $oabfile.lastwritetime write-host "Comparing this timestamp with " $basetimestamp if ($oabfile.lastwritetime -le $basetimestamp) { write-host "oab.xml file is too old ! There may be an oabgen problem !" $body = "The oab.xml (Offline Address Book) file on " + $env:ComputerName $body += " has a timestamp that is older than " + $alerthours + " hours ago`n`n" $body += "File monitored : " + $oabpath + "\oab.xml`n" $body += "File timestamp : " + $oabfile.lastwritetime #send email #$smtp = new-object Net.Mail.SmtpClient($smtpServer) $smtp.Send($msg) write-host "Email sent`n" } else { write-host "oab.xml file timestamp is ok" $body = "The oab.xml (Offline Address Book) file on " + $env:ComputerName $body += " has a timestamp as below:`n`n" $body += "File monitored : " + $oabpath + "\oab.xml`n" $body += "File timestamp : " + $oabfile.lastwritetime #send email #$smtp = new-object Net.Mail.SmtpClient($smtpServer) #$smtp.Send($emailFrom, $emailTo, $subject, $body) $smtp.Send($msg) write-host "Email sent`n" } # #
Free Windows Admin Tool Kit Click here and download it now
July 13th, 2010 5:08am

Hi, You have really changed this script very much without considering what to pass and where to pass. Above mentioned error is self descriptive: New-Object : Exception calling ".ctor" with "4" argument(s): "The parameter 'from' cannot be an empty string.Parameter name: from And this line is causing that error $msg = new-object System.Net.Mail.MailMessage $emailFrom,$emailTo,$subject,$body Obviously error is correct as you are passing emtpy parameters to constructor of MailMessage object. There is no value in $emailFrom, and i think also in $emailTo etc. Replace these lines of code: ############Create a message object and initialize####################### $msg = new-object System.Net.Mail.MailMessage $emailFrom,$emailTo,$subject,$body ############ Edit the following fields ################################## #$msg.from.Add("postmaster@sapura.com.my") $msg.to.Add("sani@sapura.com.my") $msg.cc.Add("suriya@sapura.com.my") with This ############Create a message object and initialize####################### $emailFrom ="postmaster@sapura.com.my" $emailTo= "sani@sapura.com.my" $msg = new-object System.Net.Mail.MailMessage $emailFrom,$emailTo ############ Edit the following fields ################################## $msg.cc.Add("suriya@sapura.com.my") Also you have not assigned "body" to $msg object anywhere in your code. So in both if and else block you should add this line of code $msg.Body =$body before calling $smtp.Send($msg) Hope this help you. Regards, Laeeq Qazi|Team Lead(Exchange + Sharepoint + BES + DynamicsCRM) www.HostingController.com
July 13th, 2010 11:35pm

Thank for your advice. CC is working now but there is no subject , what should i do? # # Powershell Script written by Peter Van Eeckhoutte # # Purpose : monitor the oab.xml timestamp # and report timestamp issues via email # # http://www.corelan.be:8800 # # ############Create a message object and initialize####################### $emailFrom ="postmaster@sapura.com.my" $emailTo= "sani@sapura.com.my" $msg = new-object System.Net.Mail.MailMessage $emailFrom,$emailTo ############ Edit the following fields ################################## $msg.cc.Add("suriya@sapura.com.my") $smtpServer = "send.sapura.com.my" $smtp = new-object Net.Mail.SmtpClient($smtpserver) $oabpath = "c:\Program Files\Microsoft\Exchange Server\ClientAccess\OAB\b5dbeea9-2302-4d1a-8440-b9384a3e116b" $alerthours=25 ######################################################################### # # Other vars # $subject = "Possible OABGen problem detected on " + $env:ComputerName $body="" # ###################" # # $basetimestamp=[DateTime]::Now.AddHours($alerthours*-1) # # Get timestamp of oab.xml file $oabfile = get-item $oabpath"\oab.xml" write-host "Current oab.xml timestamp : " $oabfile.lastwritetime write-host "Comparing this timestamp with " $basetimestamp if ($oabfile.lastwritetime -le $basetimestamp) { write-host "oab.xml file is too old ! There may be an oabgen problem !" $body = "The oab.xml (Offline Address Book) file on " + $env:ComputerName $body += " has a timestamp that is older than " + $alerthours + " hours ago`n`n" $body += "File monitored : " + $oabpath + "\oab.xml`n" $body += "File timestamp : " + $oabfile.lastwritetime #send email #$smtp = new-object Net.Mail.SmtpClient($smtpServer) $msg.Body=$body $smtp.Send($msg) write-host "Email sent`n" } else { write-host "oab.xml file timestamp is ok" $body = "The oab.xml (Offline Address Book) file on " + $env:ComputerName $body += " has a timestamp as below:`n`n" $body += "File monitored : " + $oabpath + "\oab.xml`n" $body += "File timestamp : " + $oabfile.lastwritetime #send email #$smtp = new-object Net.Mail.SmtpClient($smtpServer) #$smtp.Send($emailFrom, $emailTo, $subject, $body) $msg.Body=$body $smtp.Send($msg) write-host "Email sent`n" } # #
Free Windows Admin Tool Kit Click here and download it now
July 14th, 2010 8:27am

Hi, So simple: $msg.Subject = "OAB Report" OR $msg.Subject = $subject #which u have defined above You can see here what properties are available for System.Net.Mail.MailMessage http://msdn.microsoft.com/en-us/library/system.net.mail.mailmessage.aspx Regards, Laeeq Qazi|Team Lead(Exchange + Sharepoint + BES + DynamicsCRM) www.HostingController.com
July 14th, 2010 11:49am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics