SCCM 2007 to 2012 migration scripts for colletions and packages.

I am still planning to write the whole great and shiny article about my operation of SCCM 2007 to 2012 migration :], but firstly I would like to publish couple of scripts that were very helpful for me.
1. The need of changing the “parent collection” for some collections came because we plan to use SCCM for managing the servers also, but we want to limit the ability of managing them to Administrators only. We do not want helpdesk admins – that are creating packages – to deploy accidentially package on any of them, or simply to have any access to them.

New SCCM has great ability – oh my God finally!!! – to restrict permissions on particular collections. So I left collection “All system” in the root “Device collections”, later I have created collection “All Workstations Helpdesk”, with limitation to “All systems” with proper query based on OU’s that is limiting it to just workstations, and put it in the folder to which I gave permissions for my helpdesk admis.

That worked great! Helpdesk Admins didn’t have any ability to change “All Workstations Helpdesk” membership, because they didn’t have permissions for (and accually didn’t even saw) “All systems” collection. And they could buil new collections based on that collection.

Old collections had to be migrated – there were advertisements that was deployed on them, my colleagues made them to make some reports for managers, or just for themselves.

The problem was, all old collections had “parent collection” set to “All systems”. Standing in front on 400 collections I made up a decision.

– Fuck, i need a script…

So here it is:

# Here I am setting up date just for logging purposes.

$date = Get-Date
$data = Get-Date –f "yyyy-MM-dd_HH";
$log_file = "c:\SCCM_Collections_Migration_$data.log"

$All_Collections = (gc c:\Collection_Name_List.txt)


Foreach ($kolekcja in $All_Collections) {
$Collection = $kolekcja
if ($Collection -eq "All Systems")

# We take the name of the current parent collection for collection that is beind processed - just in case we want to revert changes (useful :))

$Old_Collection = (Get-WmiObject -Namespace "root\SMS\Site_WRO" -Class SMS_Collection -Filter "Name='$Collection'")
$Stara_kol = $Old_Collection.LimitToCollectionName

# Here make the change of the collection, we need to know the name of the new collection AND it's ID!

$CollectionQuery = Get-WmiObject -Namespace "root\SMS\Site_WRO" -Class SMS_Collection -Filter "Name='$Collection'"
$CollectionQuery.LimitToCollectionName = "All Workstations"
$CollectionQuery.LimitToCollectionID = "WRO0000B"

#Just for logging pusposes - taking the new collection name - to be sure it has changed

$New_Collection = (Get-WmiObject -Namespace "root\SMS\Site_WRO" -Class SMS_Collection -Filter "Name='$Collection'")
$Nowa_kol = $New_Collection.LimitToCollectionName

# Here we are writing output to the file, if the names od ids are not the same - the error is being writed to the file. The error logging is maybe not so sophisticated but is enought 🙂

if (($Old_Collection.LimitToCollectionName -ne $New_Collection.LimitToCollectionName) -and ($Old_Collection.LimitToCollectionID -ne $New_Collection.LimitToCollectionID)) {
$Data_row = "Success, for collection "+$Collection+" old limiting collection "+$Stara_kol+" has been changed to "+$Nowa_kol
Add-Content $log_file "$Data_row"
} else {
$Data_row = "ERROR The problem occured when changing the parent collection!"
Add-Content $log_file "$Data_row"


The problem I met was migration of packages. Before running the migration I didn’t realize the problem, hance I was really fucking astonished when after migration the packages/advertisements I saw in distmgr.log flood of errors saying that SCCM cannot find appropriate path for sources.

I was like:


Apparently I have missed one fundamental thing – migration taks do not migrate sources and do not change the path on it.

Well… shit 🙂

I have moved the sources but I was left with almoust hundred of packages in which I had to change path to sources. Additionally I have noticed that some packages had relative path, and some not.

Here is a script for that, :

$CollectionQuery = Get-WmiObject -Namespace "root\SMS\Site_WRO" -Class SMS_Package

Foreach ($Pakiet in $CollectionQuery) {
$Sciezka = $Pakiet.PkgSourcePath
$Poprawka = $Sciezka.Replace("D:\<LOCAL_PATH.","\\<NEW_SCCM_SERVER>\E$").Replace("\\<OLD_SCCM_SERVER>\d$","\\<NEW_SCCM_SERVER>\E$")
$Pakiet.PkgSourcePath = $Poprawka