|
2 | 2 | .NOTES |
3 | 3 | =========================================================================== |
4 | 4 | Created on: 1/9/2018 11:34 AM |
5 | | - Last Updated: 12/31/2019 |
| 5 | + Last Updated: 03/29/2020 |
6 | 6 | Author: Andrew Jimenez (asjimene) - https://github.com/asjimene/ |
7 | 7 | Filename: CMPackager.ps1 |
8 | 8 | =========================================================================== |
@@ -37,11 +37,11 @@ DynamicParam { |
37 | 37 | } |
38 | 38 | process { |
39 | 39 |
|
40 | | - $Global:ScriptVersion = "20.02.23.0" |
| 40 | + $Global:ScriptVersion = "20.03.29.0" |
41 | 41 |
|
42 | 42 | $Global:ScriptRoot = $PSScriptRoot |
43 | 43 |
|
44 | | - if (-not (Test-Path "$ScriptRoot\CMPackager.prefs" -ErrorAction SilentlyContinue)){ |
| 44 | + if (-not (Test-Path "$ScriptRoot\CMPackager.prefs" -ErrorAction SilentlyContinue)) { |
45 | 45 | $Setup = $true |
46 | 46 | } |
47 | 47 | ## Global Variables (Only load if not setup) |
@@ -1356,6 +1356,59 @@ Combines the output from Get-ChildItem with the Get-ExtensionAttribute function, |
1356 | 1356 | Return $Success |
1357 | 1357 | } |
1358 | 1358 |
|
| 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 | + |
1359 | 1412 | Function Send-EmailMessage { |
1360 | 1413 | Add-LogContent "Sending Email" |
1361 | 1414 | $Global:EmailBody += "`n`nThis message was automatically generated" |
@@ -1546,11 +1599,11 @@ Combines the output from Get-ChildItem with the Get-ExtensionAttribute function, |
1546 | 1599 | }) |
1547 | 1600 |
|
1548 | 1601 | $WPFbuttonQueryCols.Add_Click( { |
1549 | | - $form.Cursor = "Wait" |
| 1602 | + $form.Cursor = "Wait" |
1550 | 1603 | Connect-ConfigMgr |
1551 | 1604 | Push-Location |
1552 | 1605 | 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) } |
1554 | 1607 | Pop-Location |
1555 | 1608 | $form.Cursor = "Arrow" |
1556 | 1609 | }) |
@@ -1609,11 +1662,11 @@ Combines the output from Get-ChildItem with the Get-ExtensionAttribute function, |
1609 | 1662 | if (-not [System.String]::IsNullOrEmpty($FoundSiteCode)) { |
1610 | 1663 | $WPFtextBoxSiteCode.Text = $FoundSiteCode |
1611 | 1664 | } |
1612 | | -Update-GUI |
| 1665 | + Update-GUI |
1613 | 1666 | }) |
1614 | 1667 |
|
1615 | 1668 | $WPFbuttonSave.Add_Click( { |
1616 | | - $form.Cursor = "Wait" |
| 1669 | + $form.Cursor = "Wait" |
1617 | 1670 | foreach ($key in $Global:XMLtoDisplayHash.Keys) { |
1618 | 1671 | $DisplayVariable = Get-Variable $XMLtoDisplayHash[$key] -ValueOnly |
1619 | 1672 | switch -wildcard ($XMLtoDisplayHash[$key]) { |
@@ -1685,39 +1738,46 @@ Update-GUI |
1685 | 1738 | ## Begin Looping through all the Recipes |
1686 | 1739 | ForEach ($Recipe In $RecipeList) { |
1687 | 1740 | ## 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 |
1693 | 1747 |
|
1694 | 1748 | ## Import Recipe |
1695 | 1749 | Add-LogContent "Importing Content for $Recipe" |
1696 | 1750 | Write-Output "Begin Processing: $Recipe" |
1697 | 1751 | [xml]$ApplicationRecipe = Get-Content "$PSScriptRoot\Recipes\$Recipe" |
1698 | 1752 |
|
1699 | 1753 | ## Perform Packaging Tasks |
| 1754 | + Write-Output "Download" |
1700 | 1755 | $Download = Start-ApplicationDownload -Recipe $ApplicationRecipe |
1701 | | - Add-LogContent "Continue to Download: $Download" |
| 1756 | + Add-LogContent "Continue to ApplicationCreation: $Download" |
1702 | 1757 | If ($Download) { |
1703 | | - Write-Output "Download" |
| 1758 | + Write-output "Application Creation" |
1704 | 1759 | $ApplicationCreation = Invoke-ApplicationCreation -Recipe $ApplicationRecipe |
1705 | | - Add-LogContent "Continue to ApplicationCreation: $ApplicationCreation" |
| 1760 | + Add-LogContent "Continue to DeploymentTypeCreation: $ApplicationCreation" |
1706 | 1761 | } |
1707 | 1762 | If ($ApplicationCreation) { |
1708 | | - Write-Output "Application Creation" |
| 1763 | + Write-Output "Application Deployment Type Creation" |
1709 | 1764 | $DeploymentTypeCreation = Add-DeploymentType -Recipe $ApplicationRecipe |
1710 | | - Add-LogContent "Continue to DeploymentTypeCreation: $DeploymentTypeCreation" |
| 1765 | + Add-LogContent "Continue to ApplicationDistribution: $DeploymentTypeCreation" |
1711 | 1766 | } |
1712 | 1767 | If ($DeploymentTypeCreation) { |
1713 | 1768 | Write-Output "Application Distribution" |
1714 | 1769 | $ApplicationDistribution = Invoke-ApplicationDistribution -Recipe $ApplicationRecipe |
1715 | | - Add-LogContent "Continue to ApplicationDistribution: $ApplicationDistribution" |
| 1770 | + Add-LogContent "Continue to Application Supersedence: $ApplicationDistribution" |
1716 | 1771 | } |
1717 | 1772 | 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) { |
1718 | 1778 | Write-Output "Application Deployment" |
1719 | 1779 | $ApplicationDeployment = Invoke-ApplicationDeployment -Recipe $ApplicationRecipe |
1720 | | - Add-LogContent "Continue to ApplicationDeployment: $ApplicationDeployment" |
| 1780 | + Add-logContent "Completed Processing of $Recipe" |
1721 | 1781 | } |
1722 | 1782 | if ($Global:TemplateApplicationCreatedFlag -eq $true) { |
1723 | 1783 | 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." |
|
0 commit comments