Skip to content

Commit 935c25c

Browse files
authored
Merge pull request #33 from asjimene/Supersedence
New Feature: Application Supersedence
2 parents bb96391 + 3ff95d6 commit 935c25c

File tree

2 files changed

+86
-19
lines changed

2 files changed

+86
-19
lines changed

CMPackager.ps1

Lines changed: 79 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
.NOTES
33
===========================================================================
44
Created on: 1/9/2018 11:34 AM
5-
Last Updated: 12/31/2019
5+
Last Updated: 03/29/2020
66
Author: Andrew Jimenez (asjimene) - https://github.com/asjimene/
77
Filename: CMPackager.ps1
88
===========================================================================
@@ -37,11 +37,11 @@ DynamicParam {
3737
}
3838
process {
3939

40-
$Global:ScriptVersion = "20.02.23.0"
40+
$Global:ScriptVersion = "20.03.29.0"
4141

4242
$Global:ScriptRoot = $PSScriptRoot
4343

44-
if (-not (Test-Path "$ScriptRoot\CMPackager.prefs" -ErrorAction SilentlyContinue)){
44+
if (-not (Test-Path "$ScriptRoot\CMPackager.prefs" -ErrorAction SilentlyContinue)) {
4545
$Setup = $true
4646
}
4747
## Global Variables (Only load if not setup)
@@ -1356,6 +1356,59 @@ Combines the output from Get-ChildItem with the Get-ExtensionAttribute function,
13561356
Return $Success
13571357
}
13581358

1359+
function Invoke-ApplicationSupersedence {
1360+
param (
1361+
$Recipe
1362+
)
1363+
1364+
$ApplicationName = $Recipe.ApplicationDef.Application.Name
1365+
$ApplicationPublisher = $Recipe.ApplicationDef.Application.Publisher
1366+
If (-not ([string]::IsNullOrEmpty($Recipe.ApplicationDef.Supersedence.Supersedence))) {
1367+
$SupersedenceEnabled = [System.Convert]::ToBoolean($Recipe.ApplicationDef.Supersedence.Supersedence)
1368+
}
1369+
else {
1370+
$SupersedenceEnabled = $false
1371+
}
1372+
1373+
If (-not ([string]::IsNullOrEmpty($Recipe.ApplicationDef.Supersedence.Uninstall))) {
1374+
$UninstallOldApp = [System.Convert]::ToBoolean($Recipe.ApplicationDef.Supersedence.Uninstall)
1375+
}
1376+
else {
1377+
$UninstallOldApp = $false
1378+
}
1379+
1380+
Write-Host "Supersedence is $SupersedenceEnabled"
1381+
if ($SupersedenceEnabled) {
1382+
# Get the Previous Application Deployment Type
1383+
Push-Location
1384+
Set-Location $CMSite
1385+
$Latest2Apps = Get-CMApplication -Name "$ApplicationName*" -Fast | Where-Object Manufacturer -eq $ApplicationPublisher | Sort-Object DateCreated | Select-Object -first 2
1386+
Write-Host "Latest 2 apps = $($Latest2Apps.LocalizedDisplayName)"
1387+
if ($Latest2Apps.Count -eq 2) {
1388+
$NewApp = $Latest2Apps | Select-Object -Last 1
1389+
$OldApp = $Latest2Apps | Select-Object -First 1
1390+
Write-Host "Old: $($oldapp.LocalizedDisplayName) New: $($newapp.LocalizedDisplayName)"
1391+
1392+
# Check that the DeploymentTypes and Deployment Type Names Match if not, skip supersedence
1393+
$NewAppDeploymentTypes = Get-CMDeploymentType -ApplicationName $NewApp.LocalizedDisplayName | Sort-Object LocalizedDisplayName
1394+
$OldAppDeploymentTypes = Get-CMDeploymentType -ApplicationName $OldApp.LocalizedDisplayName | Sort-Object LocalizedDisplayName
1395+
1396+
Foreach ($DeploymentType in $NewAppDeploymentTypes) {
1397+
Write-Host "Superseding $($DeploymentType.LocalizedDisplayName)"
1398+
$SupersededDeploymentType = $OldAppDeploymentTypes | Where-Object LocalizedDisplayName -eq $DeploymentType.LocalizedDisplayName
1399+
if ($UninstallOldApp) {
1400+
Add-CMDeploymentTypeSupersedence -SupersedingDeploymentType $DeploymentType -SupersededDeploymentType $SupersededDeploymentType -IsUninstall $true | Out-Null
1401+
}
1402+
else {
1403+
Add-CMDeploymentTypeSupersedence -SupersedingDeploymentType $DeploymentType -SupersededDeploymentType $SupersededDeploymentType | Out-Null
1404+
}
1405+
}
1406+
}
1407+
Pop-Location
1408+
}
1409+
Write-Output $true
1410+
}
1411+
13591412
Function Send-EmailMessage {
13601413
Add-LogContent "Sending Email"
13611414
$Global:EmailBody += "`n`nThis message was automatically generated"
@@ -1546,11 +1599,11 @@ Combines the output from Get-ChildItem with the Get-ExtensionAttribute function,
15461599
})
15471600

15481601
$WPFbuttonQueryCols.Add_Click( {
1549-
$form.Cursor = "Wait"
1602+
$form.Cursor = "Wait"
15501603
Connect-ConfigMgr
15511604
Push-Location
15521605
Set-Location $Global:CMSite
1553-
(Get-CMDeviceCollection "$($WPFcomboBoxPreferredDeployColl.Text)*") | ForEach-Object { $WPFcomboBoxPreferredDeployColl.Items.Add($_.Name) }
1606+
(Get-CMDeviceCollection -Name "$($WPFcomboBoxPreferredDeployColl.Text)*") | ForEach-Object { $WPFcomboBoxPreferredDeployColl.Items.Add($_.Name) }
15541607
Pop-Location
15551608
$form.Cursor = "Arrow"
15561609
})
@@ -1609,11 +1662,11 @@ Combines the output from Get-ChildItem with the Get-ExtensionAttribute function,
16091662
if (-not [System.String]::IsNullOrEmpty($FoundSiteCode)) {
16101663
$WPFtextBoxSiteCode.Text = $FoundSiteCode
16111664
}
1612-
Update-GUI
1665+
Update-GUI
16131666
})
16141667

16151668
$WPFbuttonSave.Add_Click( {
1616-
$form.Cursor = "Wait"
1669+
$form.Cursor = "Wait"
16171670
foreach ($key in $Global:XMLtoDisplayHash.Keys) {
16181671
$DisplayVariable = Get-Variable $XMLtoDisplayHash[$key] -ValueOnly
16191672
switch -wildcard ($XMLtoDisplayHash[$key]) {
@@ -1685,39 +1738,46 @@ Update-GUI
16851738
## Begin Looping through all the Recipes
16861739
ForEach ($Recipe In $RecipeList) {
16871740
## Reset All Variables
1688-
$Download = $False
1689-
$ApplicationCreation = $False
1690-
$DeploymentTypeCreation = $False
1691-
$ApplicationDistribution = $False
1692-
$ApplicationDeployment = $False
1741+
$Download = $false
1742+
$ApplicationCreation = $false
1743+
$DeploymentTypeCreation = $false
1744+
$ApplicationDistribution = $false
1745+
$ApplicationSupersedence = $false
1746+
$ApplicationDeployment = $false
16931747

16941748
## Import Recipe
16951749
Add-LogContent "Importing Content for $Recipe"
16961750
Write-Output "Begin Processing: $Recipe"
16971751
[xml]$ApplicationRecipe = Get-Content "$PSScriptRoot\Recipes\$Recipe"
16981752

16991753
## Perform Packaging Tasks
1754+
Write-Output "Download"
17001755
$Download = Start-ApplicationDownload -Recipe $ApplicationRecipe
1701-
Add-LogContent "Continue to Download: $Download"
1756+
Add-LogContent "Continue to ApplicationCreation: $Download"
17021757
If ($Download) {
1703-
Write-Output "Download"
1758+
Write-output "Application Creation"
17041759
$ApplicationCreation = Invoke-ApplicationCreation -Recipe $ApplicationRecipe
1705-
Add-LogContent "Continue to ApplicationCreation: $ApplicationCreation"
1760+
Add-LogContent "Continue to DeploymentTypeCreation: $ApplicationCreation"
17061761
}
17071762
If ($ApplicationCreation) {
1708-
Write-Output "Application Creation"
1763+
Write-Output "Application Deployment Type Creation"
17091764
$DeploymentTypeCreation = Add-DeploymentType -Recipe $ApplicationRecipe
1710-
Add-LogContent "Continue to DeploymentTypeCreation: $DeploymentTypeCreation"
1765+
Add-LogContent "Continue to ApplicationDistribution: $DeploymentTypeCreation"
17111766
}
17121767
If ($DeploymentTypeCreation) {
17131768
Write-Output "Application Distribution"
17141769
$ApplicationDistribution = Invoke-ApplicationDistribution -Recipe $ApplicationRecipe
1715-
Add-LogContent "Continue to ApplicationDistribution: $ApplicationDistribution"
1770+
Add-LogContent "Continue to Application Supersedence: $ApplicationDistribution"
17161771
}
17171772
If ($ApplicationDistribution) {
1773+
Write-Output "Application Supersedence"
1774+
$ApplicationSupersedence = Invoke-ApplicationSupersedence -Recipe $ApplicationRecipe
1775+
Add-LogContent "Continue to Application Deployment: $ApplicationSupersedence"
1776+
}
1777+
If ($ApplicationSupersedence) {
17181778
Write-Output "Application Deployment"
17191779
$ApplicationDeployment = Invoke-ApplicationDeployment -Recipe $ApplicationRecipe
1720-
Add-LogContent "Continue to ApplicationDeployment: $ApplicationDeployment"
1780+
Add-logContent "Completed Processing of $Recipe"
17211781
}
17221782
if ($Global:TemplateApplicationCreatedFlag -eq $true) {
17231783
Add-LogContent "WARN (LEGACY): The Requirements Application has been created, please do the following:`r`n1. Add an `"Install Behavior`" entry to the `"Templates`" deployment type of the $RequirementsTemplateAppName Application`r`n2. Run the CMPackager again to finish prerequisite setup and begin packaging software.`r`nExiting."

Recipes/Template.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,13 @@
334334
<!-- DistributeToGroup - [String] Name of Distribution Point Group to distribute the Content to -->
335335
<DistributeToGroup>All DPs except PXE</DistributeToGroup>
336336
</Distribution>
337+
<!-- You can automatically supersede the previous version of the application (Note that the Previous version has to have the same name, publisher and deployment type names)-->>
338+
<Supersedence>
339+
<!-- Supersede this application automatically -->
340+
<Supersedence>[Boolean]</Supersedence>
341+
<!-- Uninstall previous version before installing the latest -->
342+
<Uninstall>[Boolean]</Uninstall>
343+
</Supersedence>
337344
<!-- You can optionally deploy the application to a specified Collection here -->
338345
<Deployment>
339346
<!-- DeploySoftware - [Boolean] Switch for Software Deployment, Application should be distributed before deployment -->

0 commit comments

Comments
 (0)