Feb
During our current project we needed to change some program attributes for all programs / applications. The amount of packages was well over 300 and the amount of programs was even more. Therefore I decided a script had to be made.
This script loops through the SMS_Package table / view in SCCM (database) and adjusts all programs based on the input in the script. The script can also be adjusted that it skips certain groups / folders, but that wasn’t needed for this project.
Note: Check the subscript at the bottom of the page for the ‘skip folder’ addition.
adjust_program_attributes.vbs
''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' AUTHOR : http://www.hican.net - @hicannet ' DATE : 13-02-2012 ' COMMENT : This script adjusts the properties of ' Application / Package Programs in SCCM. ''''''''''''''''''''''''''''''''''''''''''''''''''''''' Option Explicit Dim swbemLocator, swbemconnection, providerLoc, Location Dim sConnect, PackageFound, ProgramFound, Packages, Package Dim PackageID, Programs, Program, adjustProgram, programQuery Dim RUN_ON_SPECIFIED_PLATFORMS, wbemFlagForwardOnly Dim wbemFlagReturnImmediately, tempSupportedPlatform(3) Dim tempSupportedPlatformsArray, programPath, checkPlatformValue Dim allProgramsForPackage sConnect = "<SERVERNAME>" ConnectToSCCM AdjustPrograms() Wscript.Echo "Finished!" Wscript.Quit ''''''''''''''''''''''''''''' ' FUNCTIONS ' ''''''''''''''''''''''''''''' Function ConnectToSCCM On Error Resume Next Set swbemLocator = CreateObject("WbemScripting.SWbemLocator") Set swbemconnection = swbemLocator.ConnectServer(sConnect, "root\sms") Set providerLoc = swbemconnection.InstancesOf("SMS_ProviderLocation") For Each Location In providerLoc If location.ProviderForLocalSite = True Then Set swbemconnection = swbemLocator.ConnectServer(Location.Machine, "root\sms\site_" + Location.SiteCode) Exit For End If Next If Err.Number <> 0 Then Wscript.echo "Unable to connect to the SCCM provider. " & _ "Check the connection and / or the settings in the script!" & _ "The script will be stopped now." WScript.Quit End If On Error GoTo 0 End Function Function AdjustPrograms() Set Packages = swbemconnection.ExecQuery("Select * From SMS_Package") For Each Package In Packages PackageID = Package.PackageID programQuery = "SELECT * FROM SMS_Program WHERE PackageID='" & PackageID & "'" Set allProgramsForPackage = swbemconnection.ExecQuery(programQuery, , wbemFlagForwardOnly Or wbemFlagReturnImmediately) For Each program In allProgramsForPackage 'Set the flags according to your environment! 'program.ProgramFlags = "" 'All x86 Windows XP Set tempSupportedPlatform(0) = swbemconnection.Get("SMS_OS_Details").SpawnInstance_ tempSupportedPlatform(0).MaxVersion = "5.10.9999.9999" tempSupportedPlatform(0).MinVersion = "5.10.0000.0" tempSupportedPlatform(0).Name = "Win NT" tempSupportedPlatform(0).Platform = "I386" 'All x86 Windows 7 Set tempSupportedPlatform(1) = swbemconnection.Get("SMS_OS_Details").SpawnInstance_ tempSupportedPlatform(1).MaxVersion = "6.10.9999.9999" tempSupportedPlatform(1).MinVersion = "6.10.0000.0" tempSupportedPlatform(1).Name = "Win NT" tempSupportedPlatform(1).Platform = "I386" 'All x64 Windows XP Professional Set tempSupportedPlatform(2) = swbemconnection.Get("SMS_OS_Details").SpawnInstance_ tempSupportedPlatform(2).MaxVersion = "5.20.9999.9999" tempSupportedPlatform(2).MinVersion = "5.20.3790.0" tempSupportedPlatform(2).Name = "Win NT" tempSupportedPlatform(2).Platform = "x64" 'All x64 Windows 7 Professional Set tempSupportedPlatform(3) = swbemconnection.Get("SMS_OS_Details").SpawnInstance_ tempSupportedPlatform(3).MaxVersion = "6.10.9999.9999" tempSupportedPlatform(3).MinVersion = "6.10.0000.0" tempSupportedPlatform(3).Name = "Win NT" tempSupportedPlatform(3).Platform = "x64" program.SupportedOperatingSystems = tempSupportedPlatform program.Put_ Next Next End Function
To get this working with the above script, replace AdjustPrograms() with CheckFolder and as you can see, AdjustPrograms() will be called from within this new function.
Addition to above script to skip certain folders in SCCM:
Dim Folders, Folder, objConnectionDB Dim objCommand, objRecordSet, objOutput Dim sSplit, n, objQuery, sPackageName Set objRecordSet = CreateObject("ADODB.Recordset") Set objConnectionDB = CreateObject("ADODB.Connection") objConnectionDB.Open "Provider=SQLOLEDB;Data Source=<SERVER>;" & "Trusted_Connection=Yes;Initial Catalog=<SITE>;" Function CheckFolder() objQuery = "SELECT * FROM vPackage " & _ "INNER JOIN vFolderMembers ON vPackage.PkgID = vFolderMembers.InstanceKey " & _ "INNER JOIN vSMS_Folders ON vFolderMembers.ContainerNodeID = vSMS_Folders.ContainerNodeID " & _ "WHERE vSMS_Folders.Name <> 'Server Tooling' " & _ "AND vSMS_Folders.Name <> 'Decommissioned'" objRecordSet.Open objQuery, objConnectionDB, adOpenStatic, adLockOptimistic objRecordSet.MoveFirst Do Until objRecordSet.EOF objOutput = "" For n = 0 To objRecordSet.Fields.Count - 1 objOutput = objOutput & ";" & Trim(objRecordSet.Fields(n)) Next sSplit = Split(objOutput, ";") sPackageName = sSplit(2) AdjustPrograms(sPackageName) objRecordSet.MoveNext Loop End Function