How to change the SCCM 2012 Package Source Path with PowerShell

Let’s assume you’ve just created a larger number of packages within SCCM 2012 and then you’re asked to move the package sources to a different location. I guess no-one on earth would want to visit each package and update the data source manually, So I wrote 2 scripts that automate this task. It could actually be done with one script, but when it comes to changing such things I prefer to validate things.

As you can see from the screen shot below, we have 2 packages, with their Source Folder pointing to \\labsccm01\sources\Packages\App1 and \\labsccm01\sources\Packages\App2

package1

Now we want to change the Source path from \\labsccm01\sources\Packages\App1 to \\labsccm01\sources\NewPackages\App1 and \\labsccm01\sources\Packages\App2 to \\labsccm01\sources\NewPackages\App2

The script does not move the actual content, so before running the scripts below, the source must be copied to the new location.

First we are going to look for packages that have their content stored under \\labsccm01\sources\Packages by running the following PowerShell script.

Note: Before running the below script make sure you’re connected to the site through PowerShell.  Also make sure to set the variable $OldPath1 according to your environment.

 

The output generated looks as following.

packag2

If we are sure that these are the packages we want to change, we copy paste the content and store into a new file called Update_Package_SrcPath.txt. Then open CMPackage_Update_SourcePath.ps1 containing the code below. Edit the variables $OldPath, $OldPath1 and $NewPath. If you just want to simulate things, add –whatif to the line that starts with Set-CMPackage

package3

Going back to the Console we see the updated Source folders.

pacakge4

5 Replies to “How to change the SCCM 2012 Package Source Path with PowerShell”

  1. Hi Alex,

    In your first screenshot, I want to run a command that lists list all of the packages in the folder. So the output would list this when I run the command:

    Test Package 1
    Test Package 2

    I have Get-CMPackage | Select-object Name | where ______________________

    And I need to figure out how to filter the packages by any folder I want, like yours would be \\NL1\Package\Test Packages\

    Any ideas?

Leave a Reply