VBScript to Remap your Outlook Profiles to a new server.
April 16, 2008 on 1:45 pm | In General Programming |Recently recovered from an incident involving the slow and painful death of a MS Exchange Server. Right smack in the middle of the day, with some 800 mailboxes on that one host. We restored the mail stores to another Exchange Server, and ran a hack script to go and correct the homeMDB, homeMTA, and msExchMailServer attributes in the AD to point to the new host. That was the easy part. Then we had all these users with outlook profiles pointing to a dead server. Outlook may be resilient in picking the right server when you point it to the wrong server, but if the wrong server (to which is is pointed) is not available - as in if the server it’s pointed at is DEAD, then it doesn’t know to get the new info from the AD to point you to the correct one. This, of course, is exactly what happened to me an my ilk. We had some hundreds of users without profiles pointing to the right host. You’ve heard of Autoconfig for Outlook 2007, but that only works for NEW profiles, not existing ones suddenly pointing to a dead host. So what to do? Manually have all the users repoint their profiles by talking them through the Mail Control Panel widgets? NO! That’s expensive. Instead, write a script and deploy it as a login script.
Why a Login script? Well, because this script affects the HKEY_CURRENT_USER registry hive which only exists for a particular user when that user is logged on. At least for all intents and purposes that’s true. I think it may be possible to somehow enumerate all users on the HKEY_USERS hive, but I didn’t go that far. I apologize up front for not going the extra mile on this one, but hey, look! A free script.
NOTE: If you copy and paste it, and get a compile error, check for abberant the new-line characters caused by the squishing of my code by the text rendering on the page.
'------------------------------–
'Script RepointProfile.vbs
'Author: Dave Dolan
'Purpose: Repoints exchange profiles to use NewServer instead of OldServer
'------------------------------–
'(Editable Constants) Change OldServer and NewServer below as appropirate for the task
'----------------------------
CONST OldServer = "OldMailHostName"
CONST NewServer = "NewMailHostName"
'----------------------------
' Command Line Usage:
'------------------–
' RepointProfile.vbs [/print:true|false]
' -- (optional) print parameter when set to 'true' displays what it's doing, otherwise it prints nothing
' ---------------------------------------------------------–
' NOTE: VERY IMPORTANT: Run this in the context of the current user to change the profile settings,
' since it affects HKEY_CURRENT_USER!
'----------------------------------------------------------------------
'--------- Edit NOTHING Below this line ----------------------
'if they have non-exchange profiles, they're gonna throw (harmless if skipped) errors. I care not.
on error resume next
CONST NetBiosValue = "001e6602"
CONST FQDNValue = "001e6608"
CONST xFiveHundredValue = "001e6612"
Const HKEY_CURRENT_USER = &H80000001
printParam = Wscript.Arguments.Named("print")
if len(printParam) >= 0 then
if ucase(printParam) = "TRUE" then
printValues = 1
else
printValues = 0
end if
else
printValues = 0
end if
computerName = "."
const BASE_KEY = "Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\Profiles"
set objReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & computerName & "\root\default:StdRegProv")
objReg.EnumKey HKEY_CURRENT_USER, BASE_KEY, arrSubKeys
for each subkey in arrSubKeys
if printValues = 1 then
Wscript.Echo "Subkey = " & subkey
end if
subKeyPath = BASE_KEY & "\" & subkey & "\" & "13dbb0c8aa05101a9bb000aa002fc45a"
objReg.GetStringValue HKEY_CURRENT_USER, subKeyPath, NetBiosValue, nbServerName
objReg.GetStringValue HKEY_CURRENT_USER, subKeyPath, FQDNValue, fqdn
objReg.GetStringValue HKEY_CURRENT_USER, subKeyPath, xFiveHundredValue, X500
fqdn = ucase(fqdn)
if printValues = 1 then
Wscript.Echo "Current Values"
Wscript.Echo "------------–"
Wscript.Echo "Netbios Value: " & nbServerName
Wscript.Echo "FQDN Value: " & lcase(fqdn)
Wscript.Echo "X500 Value: " & X500
end if
if instr(nbServerName, OldServer) then
nbServerName = Replace(ucase(nbServerName), OldServer, NewServer)
fqdn = lcase(Replace(fqdn, OldServer, NewServer))
x500 = Replace(X500, OldServer, NewServer)
objReg.SetStringValue HKEY_CURRENT_USER, subKeyPath, NetBiosValue, nbServerName
objReg.SetStringValue HKEY_CURRENT_USER, subKeyPath, FQDNValue, fqdn
objReg.SetStringValue HKEY_CURRENT_USER, subKeyPath, xFiveHundredValue, X500
if printValues = 1 then
Wscript.Echo ""
Wscript.Echo "New Values"
Wscript.Echo "------------–"
Wscript.Echo "Netbios Value: " & nbServerName
Wscript.Echo "FQDN Value: " & fqdn
Wscript.Echo "X500 Value: " & X500
end if
end if
next
set objReg = nothing
4 Comments »
RSS feed for comments on this post. TrackBack URI
Leave a comment
Powered by WordPress with Pool theme design by Borja Fernandez.
Entries and comments feeds.
Valid XHTML and CSS. ^Top^

This is a great!! I\’ve been looking all over the net for this!! Thank you!!
Comment by Farkhad — June 10, 2008 #
good work and well done really . also you said a pointy of restoring Exchange on other server can you share the steps with me my mail is mohtaw2@hotmail.com
Comment by mohtaw — June 10, 2008 #
If you want to do it the normal way do this
If you’d like to upgrade 2003 to 2007 in the process, restore your exhange 2003 db’s to a dummy server from whatever backup tool you have. Mount the db’s, and then move the mailboxes using the ‘move mailbox’ option, of all things to plunk them all down on the separately configured exchange 2007 box. I know it takes a lot of hardware, but it just so happens we had that available for us.
I actually used an ADSI script to go through and change all of the people’s entries in the LDAP itself to remap the homeMDB, homeMTA, and msExchMailServer attributes to the NEW server (using a similar Replace() command as above.) I actually am not anywhere near that script, and I honestly don’t feel like writing it over again.
I believe in helping people, especially helping people learn, but not continuously doing things for people at my own expense
Haha. Good luck.
Comment by Dave — June 10, 2008 #
thanks alot for the info sahring . my case is the server contain the PDC and exchange 2003 . im planning for a full disaster recovery . i could so far restore the AD and im now searching how to restore the exchange . i back up the info store . so i imagine in case of a disaster i will have that backup only . so can you help me in this
Comment by mohtaw — June 10, 2008 #