Package & Application Source Modification Scripts

Package & Application Source Modification Scripts

  • Comments 1
  • 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.