Wednesday, June 26, 2013

change Source Path(s) in ConfigMgr 2012

i was migrating a ConfigMgr 2007 site to ComfigMgr 2012 ...
basically you can use built-in migration tool and it should work...
and yes, it even works ... in most cases
and usually you don't have to do much things afterwards.

I'm not gonna cover all the possible pitfalls right now, but only a few regarding content source location.

as it has already been explained here and there, and amog others in the blog mentioned below, Migration Tool DOES NOT / CAN NOT change the content source path!


That's not a problem, we can simply use the script from Inframon Blog to bulk update package content source.
There is however one nasty issue with that script and it should be corrected - the script is using String.Replace and this is case sensitive. This won't change anything if your $source and PkgSourcePath contain even one letter in different cases.
But it is easy to fix by adding ToLower() just before Replace :)
below is the case insensitive version to replace package source path

=====================================================

$sitecode = "XYZ"
$source = "\\OLD_PATH\sccm_source"
$dest = "\\NEW_PATH\sccm_source"

$packages = Get-WMIObject -namespace "root\sms\site_$sitecode" -class SMS_Package
foreach ($package in $packages) {
  $id = $package.PackageID
  $single = Get-WMIObject -namespace "root\sms\site_$sitecode" -class SMS_Package -filter "PackageID='$id'"

  foreach ($object in $single) {
    $path = $object.PkgSourcePath.ToLower().Replace($source, $dest)
    $object.PkgSourcePath = $path
    $object.Put()
  }
}

=====================================================

This is it....
or not yet ;)

The script above will update only the package content source path, and what about the rest?

if you've got drivers - you'll have to update driver source path as well!
the following script is a modification of the above to replace driver source path

=====================================================

$sitecode = "XYZ"
$source = "\\OLD_PATH\sccm_source"
$dest = "\\NEW_PATH\sccm_source"

$drivers = Get-WMIObject -namespace "root\sms\site_$sitecode" -class SMS_Driver
foreach ($driver in $drivers) {
  $id = $driver.CI_UniqueID
  $single = Get-WMIObject -namespace "root\sms\site_$sitecode" -class SMS_Driver -filter "CI_UniqueID='$id'"

  foreach ($object in $single) {
    $path = $object.ContentSourcePath.ToLower().Replace($source, $dest)
    $object.ContentSourcePath = $path
    $object.Put()
  }
}

=====================================================

information about WMI calsses used:
SMS_Packages - http://msdn.microsoft.com/en-us/library/cc144959.aspx
SMS_Driver - http://msdn.microsoft.com/en-us/library/cc146249.aspx

Using information from TechNet you can modify anything you want ;)

Disclaimer: the scripts are provided as-is without any warranty or support!

4 comments:

  1. How do I run this script? I made a vbs and it says invalid character on line 1 position 1

    ReplyDelete
    Replies
    1. Hmm, .ps1 works much better than .vbs ;-)

      Delete
  2. It runs, it does NOT error, it does NOTHING in the end. No path were changed for even a single driver!
    SCCM 2012 R2

    ReplyDelete