Copy SCCM 2007 Programs with PowerShell

Often times I find myself wanting to create almost identical programs for packages with maybe a slight change here or there.  Example:  I have a package that installs an application where I want one version of the install to install under user rights and the other under admin rights.

Admin Rights to allow non-admin users the ability to run the application privileged. image User rights so that all changes made with the application are in the user’s own context. image


Another example may be that I have standard program types for Install Silent, Install per user, install per-computer, etc…  If I’m always creating packages using the same program settings for each program type, it would be beneficial to be able to copy the program.

Using the below code, you can take any program from any package and copy it to another package.  You may only need to go into the properties to make slight changes to your new program and it makes it easier and quicker to quickly copy programs.


#setting up connection parameters
$strCentralSiteServer = “CentralServerName”
$strCentralSiteCode = “ABC”

#grabbing a hold of the old package
$OldProgramPackage = Get-WmiObject -computername $strCentralSiteServer -Namespace “root\sms\site_$($strCentralSiteCode)” -query “Select * from sms_package where packageid = ‘$($OldPackageID)’”

#grabbing a hold of the old program
$OldProgramProgram = Get-WmiObject -computername $strCentralSiteServer -Namespace “root\sms\site_$($strCentralSiteCode)” -query “Select * from sms_program where packageid = ‘$($OldPackageID)’ and ProgramName = ‘$($OldProgramName)’”

Using the WMI path method to get the program properties.  Without going into too much detail, the supported platforms value
copies this way.  If i just used $Prog.SupportedPLatform, the values do not migrate to the new program.
$OldProgramPath = “\\$($strCentralSiteServer)\root\sms\site_$($strCentralSiteCode):SMS_Program.PackageID=’$($OldProgramPackage.packageid)’,ProgramName=’$($OldProgramName)’”
$prog = [WMI]$OldProgramPath

#Creating a new instance of the program, assigning it to the new package, and configuring the settings for the program.
$NewProgram = ([WmiClass](“\\$script:strCentralSiteServer\root\sms\site_”+$script:strCentralSiteCode+”:SMS_Program”)).CreateInstance()

$NewProgram.ActionInProgress = $prog.ActionInProgress
$NewProgram.ApplicationHierarchy = $prog.ApplicationHierarchy
$NewProgram.CommandLine = $prog.CommandLine
$NewProgram.Comment = $prog.Comment
$NewProgram.DependentProgram = $prog.DependentProgram
$NewProgram.Description = $prog.Description
$NewProgram.DeviceFlags = $prog.DeviceFlags
$NewProgram.DiskSpaceReq = $prog.DiskSpaceReq
$NewProgram.DriveLetter = $prog.DriveLetter
$NewProgram.Duration = $prog.Duration
$NewProgram.ExtendedData = $prog.ExtendedData
$NewProgram.ExtendedDataSize = $prog.ExtendedDataSize
$NewProgram.Icon = $prog.Icon
$NewProgram.IconSize = $prog.IconSize
$NewProgram.ISVData = $prog.ISVData
$NewProgram.ISVDataSize = $prog.ISVDataSize
$NewProgram.MSIFilePath = $prog.MSIFilePath
$NewProgram.MSIProductID = $prog.MSIProductID
#New PackageID
$NewProgram.PackageID = $NewPackageID
$NewProgram.ProgramFlags = $prog.ProgramFlags
#New ProgramName
$NewProgram.ProgramName = $NewProgramName
$NewProgram.RemovalKey = $prog.RemovalKey
$NewProgram.Requirements = $prog.Requirements
$NewProgram.SupportedOperatingSystems = $prog.SupportedOperatingSystems
$NewProgram.WorkingDirectory = $prog.WorkingDirectory
#Saving the new program.

The best use I’ve had for this is to automate the package creation process by using a pre-defined package and program as a template and having your code prompt for a new package name, source, and command line.

Let me know what use you may have for this in the comments field.


Written by , Posted .

Leave a Comment

You must be logged in to post a comment.