Exporting the OOF setting is great but if you want to do more than just analyze the data you get back you need something that will read the data you exported and reset them on a mailbox. With the increased functionality of the OOF in Exchange 2007 has come extra complexity so while you could reset the OOF setting on Exchange 2007 using CDO 1.2 to make use of the extra functionality like internal and external OOF message you need to use Exchange Web Service. So watch this space for a sample.
To run the script you need to give it one cmdline parameter which is the servername of the server you want to run it against. Eg cscript exportoof.vbs servername it will write a file to c:\temp\offexport-servername.xml
I’ve put a download of the script here the script itself looks like
servername = wscript.arguments(0)Set fso = CreateObject("Scripting.FileSystemObject")
set wfile = fso.opentextfile("c:\temp\offexport-" & servername & ".xml",2,true)
wfile.writeline("<?xml version=""1.0""?>")
wfile.writeline("<ExportedOffs ExportDate=""" & WeekdayName(weekday(now),3) & ",
" & day(now()) & " " & Monthname(month(now()),3) & " " & year(now()) & " " &
formatdatetime(now(),4) & ":00" & """>")
set conn = createobject("ADODB.Connection")
set com = createobject("ADODB.Command")
Set iAdRootDSE = GetObject("LDAP://RootDSE")
strNameingContext = iAdRootDSE.Get("configurationNamingContext")
strDefaultNamingContext = iAdRootDSE.Get("defaultNamingContext")
Conn.Provider = "ADsDSOObject"
Conn.Open "ADs Provider"
svcQuery = "<LDAP://" & strNameingContext & ">;(&(objectCategory=msExchExchangeServer)(cn="
& Servername & "));cn,name,legacyExchangeDN;subtree"
Com.ActiveConnection = Conn
Com.CommandText = svcQuery
Set Rs = Com.Execute
while not rs.eof
GALQueryFilter = "(&(&(&(& (mailnickname=*)(!msExchHideFromAddressLists=TRUE)(|
(&(objectCategory=person)(objectClass=user)(msExchHomeServerName=" &
rs.fields("legacyExchangeDN") & ")) )))))"
strQuery = "<LDAP://" & strDefaultNamingContext & ">;" & GALQueryFilter & ";distinguishedName,mailnickname,mail;subtree"
com.Properties("Page Size") = 100
Com.CommandText = strQuery
Set Rs1 = Com.Execute
while not Rs1.eof
call procmailboxes(servername,rs1.fields("mail"))
wscript.echo rs1.fields("mail")
rs1.movenext
wend
rs.movenext
wend
rs.close
wfile.writeline("</ExportedOffs>")
wfile.close
set fso = nothing
set conn = nothing
set com = Nothing
wscript.echo "Done"
sub procmailboxes(servername,MailboxAlias)
Set msMapiSession = CreateObject("MAPI.Session")
on error Resume next
msMapiSession.Logon "","",False,True,True,True,Servername & vbLF & MailboxAlias
if err.number = 0 then
on error goto 0
if msMapiSession.outofoffice = false and msMapiSession.outofofficetext = "" then
wscript.echo "No OOF Data for user"
else
wfile.writeline("<OOFSetting DisplayName=""" & msMapiSession.CurrentUser & """
EmailAddress=""" & MailboxAlias & """ Offset=""" _
& msMapiSession.outofoffice & """><![CDATA[ " & msMapiSession.outofofficetext & "]]></OOFSetting>")
End if
else
Wscript.echo "Error Opening Mailbox"
end if
Set msMapiSession = Nothing
Set mrMailboxRules = Nothing
End Sub