Package & Application Source Modification Scripts
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!
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 ManagerAdminConsolebinConfigurationManager.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 (\2007ServerSource$)"
## 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 (\2012SERVERSource$)"
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 = "\2007SERVERsource$"
$NewPath = "\2012SERVERcmsource$"
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
Comments
Anonymous
January 01, 2003
Thanks @t3chn1ck!
Appreciate the community getting in and making my scripts better. :)Anonymous
January 01, 2003
@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.Anonymous
January 01, 2003
@Andreas, the scripts were written for my specific circumstance. As I put in the post, " Please TEST these in a non-production environment beforehand."
I'm sorry you the script didn't work out for you. MattAnonymous
September 03, 2013
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.Anonymous
April 18, 2014
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 :-)Anonymous
May 19, 2014
It's great!!
Thank you very much.Anonymous
May 28, 2014
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.Anonymous
September 10, 2014
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?Anonymous
February 02, 2015
Seems like it worked. Logging would be cool.Anonymous
April 15, 2015
The comment has been removedAnonymous
June 17, 2015
We also have the same Problem that some of our applications have wrong Sourcepath after running this script. We investigated some time and we found out that only applications with more than one DeploymentType have this issue
Applications with one DeploymentType have the right SourcepathAnonymous
August 31, 2015
The comment has been removed