Fixes to Microsoft Package Source Conversion Scripts

Posted on Updated on

The Microsoft PFE team blog (ConfigMgr Dogs) has a very good sample scripts  for converting Package source files to a new location.  Located from http://blogs.technet.com/b/configmgrdogs/archive/2013/05/09/package-amp-application-source-modification-scripts.aspx

However, I have found a couple of logical bugs.  The first is that when using the command “Set-CMPackage -Name $Package.Name -Path $ChangePath”, this will cause ALL packages with the same name to be converted over to the same value as listed by $ChangePath .  Instead of using parameter “-Name $Package.Name”, this code needs to use “-Id $Package.PackageID”.

There second and confirmed logical bug if that is caused by the package path being case sensitive such that the conversion of $OldPath to $NewPath fails (no errors generated).

Finally, as an enhancement, it would be good for packages that have already been converted to not be run again.

Below is my rendition of the script


# Original script from
# http://blogs.technet.com/b/configmgrdogs/archive/2013/05/09/package-amp-application-source-modification-scripts.aspx
# Modifications by https://t3chn1ck.wordpress.com

Write-Host "#######################################################################"
Write-Host "##        Matts ConfigMgr 2012 SP1 Package Source Modifier           ##"
Write-Host "##                blogs.technet.com/b/ConfigMgrDogs                  ##"
Write-Host "#######################################################################"

# Site Code + :
Set-Location "S01:"

$PackageArray = Get-CMPackage
$OldPath = "\\2007SERVER\source$"
$NewPath = "\\2012SERVER\cmsource$"

ForEach ($Package in $PackageArray){
   $OldPkgPath = $Package.PkgSourcePath.ToLower()

   If ($OldPkgPath.StartsWith("\\2007server")){
      $ChangePath = $Package.PkgSourcePath.ToLower()
      $ChangePath = $ChangePath.Replace($OldPath, $NewPath)

      Set-CMPackage -Id $Package.PackageID -Path $ChangePath
      Write-Host "Changed: " $Package.Name " to " $ChangePath -f Green
   } Else {
      Write-Host "Not changed: " $Package.Name -f DarkYellow
   }
}

Advertisements

3 thoughts on “Fixes to Microsoft Package Source Conversion Scripts

    […] page mentioned above from Matt Shadbolt  has a good script, but I’d suggest using this modified version that has some extra checks for packages that have already been updated and also removes issues […]

    ConfigMgr Content Source Path migration said:
    September 28, 2016 at 5:01 pm

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s