Friday, July 17, 2009

32 bit vs 64 bit automated install script

In my environment, we are starting to have more and more 64 bit servers which can cause agent upgrade and patching issues since OpsMgr related upgrades have separate files for each. I don't use the "repair" option in Opsmgr since it doesn't allow you to schedule the upgrades and I for one am not going to stay up till 12AM so I can upgrade the production servers.



First I created two jobs in our deployment tool to do separate 32 bit and 64 bit upgrades but that's a pain because you have to identify the servers ahead of time. I knew that there are registry keys that will distinguish between 32 bit and 64 bit so why not create a vbscript that will do that and then execute the appropriate MSI? But being a script novice, I gave this to one of my other guys here Eric H. and he cranked it out for me. Thanks Eric!

option explicit
Dim strServer : strServer = "."
Dim objShell : Set objShell = CreateObject("Wscript.Shell")

Dim strCommand : strCommand = "MsiExec.exe /uninstall {E7600A9C-6782-4221-984E-AB89C780DC2D} /qn"

objShell.Run(strCommand),1,TRUE
Dim objMsiCommand, objPath, objInstall

If Is64Bit(strServer) Then
objMsiCommand = "%WinDir%\System32\MsiExec /i "
objPath = "%WinDir%\temp"
objInstall = "\MOMAgent_R2_x64.msi /quiet USE_SETTINGS_FROM_AD=0 MANAGEMENT_GROUP=""managementgroupname"" MANAGEMENT_SERVER_DNS=fqdn_servername"

Else
objMsiCommand = "%WinDir%\System32\MsiExec /i " objPath = "%WinDir%\temp" objInstall = "\MOMAgent_r2_x86.msi /quiet USE_SETTINGS_FROM_AD=0 MANAGEMENT_GROUP="" managementgroupname"" MANAGEMENT_SERVER_DNS=fqdn_servername"

End If
Dim strCommand2 : strCommand2 = objMsiCommand & objPath & objInstall

objShell.Run(strCommand2),1,TRUE
Set objShell = Nothing

Public Function Is64Bit(strComputer)
Dim strReturnValue : strReturnValue = False
const HKEY_LOCAL_MACHINE = &H80000002
Dim strKeyPath : strKeyPath = "SOFTWARE\Wow6432Node\Microsoft\EventSystem" Dim strValueName : strValueName = "Configured"
Dim iValue
Dim oReg : Set oReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\default:StdRegProv") oReg.GetDWORDValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,iValue


If ISNull(iValue) Then
strReturnValue = False
Else
strReturnValue = True
End If
Set oReg= Nothing
Is64Bit = strReturnValue

End Function

No comments:

Post a Comment