How to update ConfigMgr Package and Application source paths

Posted: December 10, 2014 in Configuration Manager, Information, Powershell, System Center, Work in Progress
Tags: , , ,

When you need to change the location that you have been saving all your package source files, you will then need to update all the existing packages and applications to point to that new location.

(Note: See here to read what happens when you do update all your source locations)

This is fairly simple for Packages, but is a bit more complicated for Applications

Applications

cm12-applications

Changing the path for APPLICATIONS is not particularly simple, and there is no single Powershell cmdlet that allows you to do it.

cm12-applicationsource

This page has a great script from Matt Shadbolt that I used as the starting point. There were a few issues that a user made in the comments about the packages script which also applies to the application one. I have created an updated script to handle those cases, namely not making a “change” to the application when the path is not changed, and also removing issues around being case-sensitive. One challenge I’ve encountered is the speed of this script, and that the default settings limits the Powershell query to only return 1000 applications, which is an issue when you have more than 1000 applications. To resolve this, the “Set-CMQueryResultMaximum” command can increase how many results are returned

I’m still testing out various other scripts that I’ve found, so there are quite a few ways people have come up with. Below is my current (WORK IN PROGRESS) version, and I’ll add links to any others I find of interest under it also.

 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 'D:\ConfigMgr\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$)"
 $OriginalSource = $OriginalSource.ToLower()
 ## 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$)" 
 $DestinationSource = $DestinationSource.ToLower()

 Write-Host "" 
 Write-Host "Working.." 
 Write-Host "" 
 ## Get your Application Deployment Types
 
Set-CMQueryResultMaximum -maximum 10000
$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
    } 
    
    $DTCleanPath = $DTCleanPath.ToLower()
            
    $DirectoryPath = $DTCleanPath -replace [regex]::Escape($OriginalSource), "$DestinationSource"
    
 if ($DirectoryPath -eq $DTCleanPath) {
    Write-Host "No Change:" $x
    }
    Else {
    ## Modify DT path 
    
    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; 
     
    Set-CMDeploymentType –ApplicationName "$x" –DeploymentTypeName $DT.LocalizedDisplayName –MsiOrScriptInstaller –ContentLocation "$DirectoryPath" 
    
    Write-Host " has been modified to " -f White -NoNewline; 
    Write-Host $DirectoryPath -f DarkYellow 
        }
    } 
 }

Other Examples

http://www.scconfigmgr.com/2013/07/25/update-the-content-path-of-all-applications-in-configmgr-2012-with-powershell/

 

Packages

cm12-packages

Changing the path for PACKAGES is fairly straight forward as it hasn’t really changed since ConfigMgr 2007. You can use Powershell quite easily to do this in CM2012, but I do find the CoreTech Package Source Changer tool to be quite nice for this part.

The 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 around case-sensitivity.

cm12-packagesource

Comments
  1. N. Moseley says:

    Thanks for the pingback on my script. I’m glad it was useful for you.

  2. Creed Cordonier says:

    Hi there. I am new to this. Can this be modified (or does it need to be?) if I only intend to change the server name? I would like to change only the server name in the Content Location and leave the rest of the UNC paths alone. All my Applications are in different folders, like so:

    \\server name\drive letter\variable\variable

    ‘variable’ is a folder that will be different for any of my Applications. But the server name is changing.

    Thank you!

    • Scott says:

      Yes, you should be able to use it to change only the server name.

      • Creed Cordonier says:

        Excellent, thank you. Is there anything that needs modified with this script in order to do that?

        In this section of the script:

        “## 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$)”
        $OriginalSource = $OriginalSource.ToLower()
        ## 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$)”
        $DestinationSource = $DestinationSource.ToLower()”

        it looks like I would be changing \\oldservername\share to \\newservername\share, but then will the rest of the path (\\servename\share\folder\folder) stay the same in the Content Location of the Deployment Type on the new server?

        Or will it this just change the Content Location to \\newserver\share, and not include the \folder\folder which actually contains my applications?

        Thank you

        • Scott says:

          It works like a “Search-Replace” action, so the content path isn’t changed in any other way, it just replaces and matches for “string a” with “string b”

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