Fixes to Microsoft Package Source Conversion Scripts

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
   }
}

Leave a comment

Blog at WordPress.com.

Up ↑