SCCM Configmgr 2007 Script move packages to Archive Folder

This is Continuation to previous post package archival process.up on the query results,I would not delete the packages from console directly rather i delete them from its assigned Distribution points and move them to Archive folder and let be there for sometime until for sometime incase if it is required.

If you have large number of packages,you may find difficult in moving the packages by identifying where they reside (if you have subfolders).If you have less packages <10,you may use the report to know the root path of the package  and then right click on the package Move to archive folder by appending Retired to the existing package name to know package is retired.

If you have multiple packages,moving one by one is not easy thus you require something like script or tools.

Moving package using script may require to get the Source folder ContainerID number of  the packages(Folder of the package)  and Destination Folder ContainerID(Archival folder ID).

Here is the SQL query for the list of moving packages to know their Source Folder ContanerID.

 image

From the package clean up report,if you get multiple packages,just place them in IN condition separated by comma (,).

I have packageID cen00004 which i need to move to archive folder with containerID=4 from SQL query below

select  B.ContainerNodeID,B.NAME,A.InstanceKey from dbo.FolderMembers a,.dbo.Folders b where
a.ContainerNodeID=b.ContainerNodeID and b.Name like '%archive%'

Replace the folder name if you have other one.

Now we have list of packages with their source ContainerNodeID(which is nothing  but the package FolderID).

Create a VB script with below syntax with input of all package IDs separated by commas with their source folder and destination folder.

Note : Please replace quotes (‘”) as they are replaced by fancy.

Option Explicit
'On error resume next

Dim strSMSServer, strSMSSiteCode, strPackageIDs
Dim intSourceFolder, intDestFolder, intObjectType
Dim loc, objSMS
Dim objFolder
Dim arrPackageIDs
Dim retval

strSMSServer   = "SCCM server Name"
strSMSSiteCode = "SiteCode"
strPackageIDs  = inputbox("Please input packageIDs separated by commas","List of packages to be moved")

intSourceFolder =inputbox("Please input Source folder ContainerID number", "Source ContainerID")  ‘This ID is what you see in above SQL query to move all packages from the same folder test =1.
intDestFolder   =4 'Destination Folder for Archived packages :In this case,My archive package folder is 4.

intObjectType   = 2  '2=Package for type of object .This scripts works only for standard software distribution packages.

Set loc         = CreateObject("WbemScripting.SWbemLocator")
Set objSMS      = loc.ConnectServer(strSMSServer, "root\SMS\site_" & strSMSSiteCode)

Set objFolder = objSMS.Get("SMS_ObjectContainerItem")
arrPackageIDs = Split(strPackageIDs, ",")

retval = objFolder.MoveMembers(arrPackageIDs, intSourceFolder , intDestFolder , intObjectType)
If Err.Number <> 0 Then
    msgbox Err.Description
End If

MSGBOX "Script is completed"

You may get multiple packages with different source Folders.So you will have to run the script to move bulk packages from each source folder to Destination at one go.

It is better than moving one by one package each time.

Hope it helps!

Post Comment