Package & Application Source Modification Scripts

Package & Application Source Modification Scripts

  • Comments 7
  • Likes

I promised in my last post to provide you all with my scripts for modifying all your package and application source paths… well that was over two months ago now!

http://blogs.technet.com/b/configmgrdogs/archive/2013/02/18/moving-your-package-source-after-migration.aspx

Note: These scripts are provided “as-is” and no guarantees are provided. Please TEST these in a non-production environment beforehand.

 

ApplicationSourceModification.ps1 (Version 1.0)

First is my script will modify the source paths for all of your Deployment Types within all Applications that are Script or MSI installers (you can modify this to do your App-V Deployment Types too)

Write-Host "#######################################################################" -f Green
Write-Host "##        Matts ConfigMgr 2012 SP1 Application Source Modifier       ##" -f Green
Write-Host "##                blogs.technet.com/b/ConfigMgrDogs                  ##" -f Green
Write-Host "##                                                                   ##" -f Green
Write-Host "##                                                                   ##" -f Green
Write-Host "##  Please ensure your package source content has been moved to the  ##" -f Green
Write-Host "##          new location *prior* to running this script              ##" -f Green
Write-Host "##                                                                   ##" -f Green
Write-Host "#######################################################################" -f Green
Start-Sleep -s 2

Write-Host ""
Write-Host ""
## Import ConfigMgr PS Module
Import-Module 'C:\Program Files (x86)\Microsoft Configuration Manager\AdminConsole\bin\ConfigurationManager.psd1'

## Connect to ConfigMgr Site
$SiteCode = Read-Host "Enter your ConfigMgr Site code (XXX)"
$SiteCode = $SiteCode + ":"
Set-Location $SiteCode
Write-Host ""

## Set old Source share
Write-Host "NOTE: This is the location your 2007 packages are stored. It must be correct"
$OriginalSource = Read-Host "Enter your source ConfigMgr share (\\2007Server\Source$)"

## Set new Source share
Write-Host ""
Write-Host "NOTE: This is the location your Applications are stored. It must be correct"
$DestinationSource = Read-Host "Enter your destination ConfigMgr Source share (\\2012SERVER\Source$)"
Write-Host ""
Write-Host "Working.."
Write-Host ""
## Get your Application Deployment Types

$ApplicationName = Get-CMApplication
$ApplicationName = $ApplicationName.LocalizedDisplayName

ForEach($x in $ApplicationName)
{
$DeploymentTypeName = Get-CMDeploymentType -ApplicationName $x
#$DeploymentTypeName = $DeploymentTypeName.LocalizedDisplayName

    ForEach($DT in $DeploymentTypeName)
    {
    ## Change the directory path to the new location
    $DTSDMPackageXLM = $DT.SDMPackageXML
    $DTSDMPackageXLM = [XML]$DTSDMPackageXLM
   
    ## Get Path for Apps with multiple DTs
    $DTCleanPath = $DTSDMPackageXLM.AppMgmtDigest.DeploymentType.Installer.Contents.Content.Location[0]
   
    ## Get Path for Apps with single DT
    IF($DTCleanPath -eq "\")
    {
        $DTCleanPath = $DTSDMPackageXLM.AppMgmtDigest.DeploymentType.Installer.Contents.Content.Location
    }
   
    $DirectoryPath = $DTCleanPath -replace [regex]::Escape($OriginalSource), "$DestinationSource"

    ## Modify DT path
    Set-CMDeploymentType –ApplicationName "$x" –DeploymentTypeName $DT.LocalizedDisplayName –MsiOrScriptInstaller –ContentLocation "$DirectoryPath"
   
    ## Write Output
    Write-Host "Application " -f White -NoNewline;
    Write-Host $x -F Red -NoNewline;
    Write-Host " with Deployment Type " -f White -NoNewline;
    Write-Host $DT.LocalizedDisplayName -f Yellow -NoNewline;
    Write-Host " has been modified to " -f White -NoNewline;
    Write-Host $DirectoryPath -f DarkYellow
    }
}

PackageSourceModification.ps1 (Version 1.0)

My second script is much simpler, as we are changing only the Package source location, with no need to cycle through each Deployment Type

Write-Host "#######################################################################" -f Green
Write-Host "##        Matts ConfigMgr 2012 SP1 Package Source Modifier           ##" -f Green
Write-Host "##                blogs.technet.com/b/ConfigMgrDogs                  ##" -f Green
Write-Host "##                                                                   ##" -f Green
Write-Host "##                                                                   ##" -f Green
Write-Host "##  Please ensure your package source content has been moved to the  ##" -f Green
Write-Host "##          new location *prior* to running this script              ##" -f Green
Write-Host "##                                                                   ##" -f Green
Write-Host "#######################################################################" -f Green
Start-Sleep -s 2

$SiteCode = Read-Host "Enter your ConfigMgr Site code (XXX)"
$SiteCode = $SiteCode + ":"
Set-Location $SiteCode

$PackageArray = Get-CMPackage
$OldPath = "\\2007SERVER\source$"
$NewPath = "\\2012SERVER\cmsource$"
ForEach ($Package in $PackageArray)
{
$ChangePath = $Package.PkgSourcePath.Replace($OldPath, $NewPath)
Set-CMPackage -Name $Package.Name -Path $ChangePath
Write-Host $Package.Name " has been changed to " $ChangePath
}

Matt Shadbolt

Your comment has been posted.   Close
Thank you, your comment requires moderation so it may take a while to appear.   Close
Leave a Comment
  • Worked a treat.

    Just had to add the Import Module to the 2nd script.

    Also the OldPath is case sensitive so it wont replace the OldPath with NewPath if the case isnt matching.

  • I found another logical bug in the script for converting the source files of packages. By running the command "Set-CMPackage -Name $Package.Name -Path $ChangePath", this will cause ALL packages with the same name to be converted over to the $ChangePath value. Instead of using parameter "-Name $Package.Name", it needs to use "-Id $Package.PackageID".

    I can confer with Cam on the problem with the case sensitivity on oldpath/newpath.

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

    All of the above items, I have created a new script (right now just for Packages) which others can find on my blog.at http://t3chn1ck.wordpress.com/2014/04/18/fixes-to-microsoft-package-source-conversion-scripts/

    Just as stated in the original script, test in your environment first before production :-)

  • Thanks @t3chn1ck!

    Appreciate the community getting in and making my scripts better. :)

  • It's great!!
    Thank you very much.

  • Hey Matt,

    Have you run into the scenario where SDMPackageXML on the deployment type is empty? Out of a couple hundred deployment types, probably 20% are blank. I read that this is a "lazy property", and won't always be populated, but looking at the property in WMI says otherwise. I can get the SDMPackageXML to populate if I update the deployment type by adding an administrative comment, but am wondering if there is an easier way.

  • @Mike, I haven't seen that but to be honest I haven't used my own script for a while.

    In saying that, I'm sure it's quite easy to add an admin comment as part of the script if the SDMPackageXML is missing.

  • Thanks for creating these. One question, the Application script returned some errors on a few applications "Cannot index into a null array" any clues as to what that's talking about?