Bulk update commandlines in SCCM-programs
Just a small script to update the commandline of a large number of programs in SCCM.
This script will change from “/q” to “/qb!”…
Set oLocator = CreateObject("WbemScripting.SWbemLocator") Set oSccmWmi = oLocator.ConnectServer(".", "root\sms\site_C01", "", "") Set oPrograms = oSccmWmi.ExecQuery("select * from SMS_Program where CommandLine LIKE '%msiexec%/q %'") For Each oProgram In oPrograms WScript.Echo "Package: " & oProgram.PackageID & " (" & oProgram.ProgramName & ")" WScript.Echo "Orginal: " & oProgram.CommandLine sNewCmd = Replace(oProgram.CommandLine, "/q", "/qb!") WScript.Echo " New: " & sNewCmd Set oModProgram = oSccmWmi.Get("SMS_Program.PackageID='" & oProgram.PackageID & "'" & ",ProgramName='" & oProgram.ProgramName & "'") oModProgram.CommandLine = sNewCmd oModProgram.Put_ ' Comment out this line if you want to test Set oModProgram = Nothing Next
2009-03-25 07:55
Might add that you can change “anything” on a program with that code.
For instance, if you want to change the description just add:
oModProgram.Description = “My New Description”
I used that with a couple of queries to filter out install/repair/uninstall and then put them in to different categories (Description).
2009-05-27 14:27
If you have a command line like:
msiexec.exe /i MyFile.MSI TRANSFORMS=MyFile.MST /l X:\Path\MyFile.log /m /qr
And you want to remove the part “/l …. .log”
Change:
sNewCmd = Replace(oProgram.CommandLine, “/q”, “/qb!”)
To:
iLogStart = InStr(oProgram.CommandLine, “/l”)-1
iLogStop = InStr(iStart, oProgram.CommandLine, “.log”) 4
sNewCmd = Left(oProgram.CommandLine, iLogStart) & Right(oProgram.CommandLine, Len(oProgram.CommandLine)-iLogStop)