Ole Skovgaard, IT-Architect @ Infrahouse, Lersø Parkallé 107 , 2100 København Ø, Denmark

Wednesday, September 28, 2011

Run program based on Config Mgr. task sequence variables

I regularly come across tasks where it is necessary to execute an MSI or EXE file with separate parameters based on ex. geographical location, organization structure, Production/Test environment etc.
To manage this I create a script based on Task sequence variables and execute the program by using these variables.  

These Task Sequence variables can either be set as collection variables in Config Mgr. or as a fronted HTA. 

Usage: Place the script in the same package/folder as the MSI/EXE you want to execute.

This script gathers a total of five Task Sequence variables (ProductionORTest, testenvironment-BaseSERVER, testenvironment-DBSERVER, Production-DBSERVER, Production-BaseSERVER).  All the variables are set by a Fronted HTA that has been created. The variables could also have been set to Confg Mgr. collections containing machine accounts for either test or production.

In the below sample script the Task sequence variable “ProductionORTest” is used to determine if the MSI file should install an client in production environment or in test environment.


Save below sample script as ZTI-RunProgramTSvar.vbs

' //*************************************************************************
' // ***** Script Header *****
' // 
' // File: ZTI-RunProgramTSVar.vbs
' //
' // Purpose: Execute program (MSI/EXE) based on Task Sequence Variables
' //
' // Usage: cscript ZTI-RunProgramTSVar.vbs
' //
' // Script Version: 1.0.0
' //
' // 1.0.0  Created by Ole Skovgaard (www.Infrahouse.com)
' //
' // Customer History:
' //
' // ***** End Header *****
' //*************************************************************************

Onerrorresumenext

Dim objShell
Dim objFSO

Set objShell        = WScript.CreateObject("WScript.Shell")
Set objFSO          = CreateObject("Scripting.FileSystemObject")

strWinDir             = objShell.ExpandEnvironmentStrings("%SYSTEMROOT%")
strSystemDir         = objShell.ExpandEnvironmentStrings("%SYSTEMDRIVE%")

objShell.CD           = objFSO.GetParentFolderName(Wscript.ScriptFullName)
ScriptDir              = objShell.CD

Set env               = CreateObject("Microsoft.SMS.TSEnvironment")

ProductionORTest    = env("ProductionORTest")


IfLCase(ProductionORTest) = LCase("testenvironment") Then

BaseSERVER          = env("testenvironment-BaseSERVER")
DBSERVER            = env("testenvironment-DBSERVER")
Else

BaseSERVER          = env("Production-BaseSERVER")
DBSERVER            = env("Production-DBSERVER")

EndIf


Command =  "MSIEXEC /i """ & ScriptDir & "\Setup.msi"" /l*v+ " & strSystemDir & "\Setup.log /qb ALLUSERS=1 BaseSERVER=" & BaseSERVER & " DBSERVER=" & DBSERVER

irun = objShell.Run(Command, 0, true)

No comments:

Post a Comment