January 19, 2010

Script to update SMS Package

On Error Resume Next
Dim objSWbemLocator
Dim objSWbemServices
Dim ProviderLoc
Dim Location
Dim PackageID
Dim colPackages
Dim Package

'Enter the package ID of the package to be updated
PackageID = "PACKAGEID"

'To connect to the local SMS site's Provider by using SWbemLocator
Set objSWbemLocator = CreateObject("WbemScripting.SWbemLocator")

Set objSWbemServices= objSWbemLocator.ConnectServer(".", "root\sms")
Set ProviderLoc = objSWbemServices.InstancesOf("SMS_ProviderLocation")

For Each Location In ProviderLoc
If Location.ProviderForLocalSite = True Then
Set objSWbemServices = objSWbemLocator.ConnectServer _
(Location.Machine, "root\sms\site_" + Location.SiteCode)
End If
Next

'To find the package ID in the SMS_Packages class and use the RefreshPkgSource Method to initiate update.
Set colPackages = objSWbemServices.ExecQuery _
("Select * from SMS_Package where PackageID = '" & PackageID & "'")

If colPackages.count <;>; 0 Then
For Each Package In colPackages
Package.RefreshPkgSource( )
WScript.Echo "Package '" & PackageID & "' Updated!"
Next
Else
WScript.Echo "Package '" & PackageID & "' Not Found!"
End If

No comments:

Post a Comment