Quick and nifty bit of powershell for SCCM 2012.
In a dev environment, I had several OSD task sequences and associated packages imported. Each one was imported from a different source path to keep them separate, but they were all imported to the root Packages node in the console
Using the powershell cmdlets for SCCM, I used the code below to reassign them to folders based on the source path property of the package. (I manually created the folders but that’s easy to script too 🙂 )
For the example of a build named “Win8import”, with a package folder named the same;
1 2 |
$pkgs = Get-CMPackage | Where-Object {$_.PkgSourcePath -like "\\server\source\win8import*"} Move-CMObject -FolderPath "PRI:\Package\win8import" -inputobject $pkgs |
all done.
Hi Matt,
I want to run a command that lists list all of the packages in the folder. Say I have the folder
\\NL1\Package\Test Packages\ and it contains two packages, Test 1 andTest 2
So the output would list this when I run the command:
Test 1
Test 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. Any ideas?
Hey J,
unfortunately folders aren’t exposed well in the ConfigMgr cmdlets, you need to use WMI. Have a look at Peter van der Woude’s function for this here – https://gallery.technet.microsoft.com/Get-the-location-of-an-170dea5c
FYI – You can perform move actions on objects between folders with the cmdlet move-cmobject, which I often use when scripting to create an application or something, then put it in a particular folder, but this won’t help your query.
Cheers,
Matt