In large SCCM environments managing hundreds or thousands of packages can get out of hand. This VB script allows you to obtain the source path of packages that you list in a text file (one package ID per line).
In the "Set these variables" section of the script, specify your SCCM site server name and the full path to the file containing the list of package IDs.
Run it from the command prompt like this:
cscript getSourcePathPkgsInFile.vbs > output.txt
(The output is redirected to output.txt)
The script is listed below but you can also download it from Microsoft's gallery in case the copy and paste operation breaks lines incorrectly.
' by Romano Jerez
' 2011
' Script gets the source path for packages listed in sourceFile (one package ID per line)
' *** SET THESE VARIABLES ***
SCCMServer = ""
sourceFile = "c:\packages.txt"
' ***************************
Const ForReading = 1
' Connect to SMS provider
set objSwbemLocator = CreateObject("WbemScripting.SWbemLocator")
set objSWbemServices= objSWbemLocator.ConnectServer(SMSServer, "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
siteCode = Location.SiteCode
Next
Set objShell = WScript.CreateObject("WScript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile1 = objFSO.OpenTextFile(sourceFile, ForReading)
Do Until (objFile1.AtEndOfStream)
pkgID = objFile1.Readline
getPkgSource pkgID
Loop
objFile1.Close
Sub getPkgSource(PKG)
On Error Resume Next
Set objPackage = GetObject("WinMgmts:!\\" & SCCMServer & "\root\SMS\site_" & siteCode & _
":SMS_Package.PackageID='" & PKG & "'")
If Err.Number <> 0 Then
WScript.echo PKG & "," & "Invalid package - Error " & Err.Number & ": " & Err.Description
Err.Clear
Else
WScript.Echo PKG & "," & objPackage.PkgSourcePath
End If
End Sub
In the "Set these variables" section of the script, specify your SCCM site server name and the full path to the file containing the list of package IDs.
Run it from the command prompt like this:
cscript getSourcePathPkgsInFile.vbs > output.txt
(The output is redirected to output.txt)
The script is listed below but you can also download it from Microsoft's gallery in case the copy and paste operation breaks lines incorrectly.
' by Romano Jerez
' 2011
' Script gets the source path for packages listed in sourceFile (one package ID per line)
' *** SET THESE VARIABLES ***
SCCMServer = ""
sourceFile = "c:\packages.txt"
' ***************************
Const ForReading = 1
' Connect to SMS provider
set objSwbemLocator = CreateObject("WbemScripting.SWbemLocator")
set objSWbemServices= objSWbemLocator.ConnectServer(SMSServer, "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
siteCode = Location.SiteCode
Next
Set objShell = WScript.CreateObject("WScript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile1 = objFSO.OpenTextFile(sourceFile, ForReading)
Do Until (objFile1.AtEndOfStream)
pkgID = objFile1.Readline
getPkgSource pkgID
Loop
objFile1.Close
Sub getPkgSource(PKG)
On Error Resume Next
Set objPackage = GetObject("WinMgmts:!\\" & SCCMServer & "\root\SMS\site_" & siteCode & _
":SMS_Package.PackageID='" & PKG & "'")
If Err.Number <> 0 Then
WScript.echo PKG & "," & "Invalid package - Error " & Err.Number & ": " & Err.Description
Err.Clear
Else
WScript.Echo PKG & "," & objPackage.PkgSourcePath
End If
End Sub