@@ -16,8 +16,10 @@ function Retire-CMApplication {
1616
1717 # for each provided app name, remove deployments, rename, and retire
1818 foreach ($RetiringAppName in $RetiringApps ) {
19- if ($RetiringAppName = Get-CMApplication - Name $RetiringApp ) {
20- Write-Host " So long, $RetiringApp !"
19+
20+ if ($RetiringApp = Get-CMApplication - Name $RetiringAppName )
21+ {
22+ Write-Host " So long, $RetiringAppName !"
2123
2224 # checking retired status, setting to active so that we can make changes
2325 if ($RetiringApp.IsExpired )
@@ -41,12 +43,15 @@ function Retire-CMApplication {
4143 $DPs = Get-CMDistributionPoint - AllSite
4244 foreach ($DP in $DPs )
4345 {
44- $dpNetworkOSPath = $dp.NetworkOSPath # TODO: unify 2 variables
45- $dpName = ($dp.NetworkOSPath ).Substring(2 , $dpNetworkOSPath.Length - 2 )
46+ # $dpNetworkOSPath = $dp.NetworkOSPath #TODO: unify 2 variables
47+ $dpName = ($dp.NetworkOSPath ).Substring(2 )
48+
49+
50+ Write-Verbose " Removing $RetiringAppName from $dpName "
4651 Write-Host - NoNewline " ."
4752 try
4853 {
49- Remove-CMContentDistribution - ApplicationName " $RetiringApp " - DistributionPointName $dpName - Force - EA SilentlyContinue
54+ Remove-CMContentDistribution - ApplicationName " $RetiringAppName " - DistributionPointName $dpName - Force - EA SilentlyContinue # TODO: parallelize this
5055 }
5156 catch { }
5257 }
@@ -56,35 +61,37 @@ function Retire-CMApplication {
5661 foreach ($DPG in $DPGs ) {
5762 Write-Host - NoNewline " ."
5863 try {
59- Remove-CMContentDistribution - ApplicationName $RetiringAppName - DistributionPointGroupName ($DPG ).Name - Force - EA SilentlyContinue
64+ Remove-CMContentDistribution - ApplicationName " $RetiringAppName " - DistributionPointGroupName ($DPG ).Name - Force - EA SilentlyContinue # TODO: parallelize this
6065 } catch { }
6166 }
6267 Write-Host
6368
64- # rename the app
65- $RetiringAppName = $RetiringApp.Replace (' Retired-' , ' ' )
6669 If ($rename ){
67- try {
68- Set-CMApplication - Name $RetiringAppName - NewName " Retired-$RetiringApp "
69- } catch { }
70- Write-Host " Renamed to Retired-$RetiringApp ."
70+ # rename the app
71+ $RetiringAppName = $RetiringApp.Replace (' Retired-' , ' ' )
72+ try {
73+ Set-CMApplication - Name $RetiringAppName - NewName " Retired-$RetiringApp "
74+ } catch { }
75+ Write-Host " Renamed to Retired-$RetiringAppName ."
7176
72- # move the app according to category
73- if ($RetiringApp.LocalizedCategoryInstanceNames -eq " Mac" ) {
74- Move-CMObject - FolderPath " Application\Retired" - InputObject $RetiringApp
75- Write-Host " Moved to Retired."
76- } else {
77- Move-CMObject - FolderPath " Application\Retired" - InputObject $RetiringApp
78- Write-Host " Moved to Retired."
79- }
77+ # move the app according to category
78+ if ($RetiringApp.LocalizedCategoryInstanceNames -eq " Mac" ) {
79+ Move-CMObject - FolderPath " Application\Retired" - InputObject $RetiringApp
80+ Write-Host " Moved to Retired."
81+ } else {
82+ Move-CMObject - FolderPath " Application\Retired" - InputObject $RetiringApp
83+ Write-Host " Moved to Retired."
84+ }
8085 }
81-
86+
8287 # retire the app
83- if (! $RetiringApp.IsExpired ) {
84- $RetiringAppWMI = gwmi - Namespace Root\SMS\Site_ $PSD - class SMS_ApplicationLatest - Filter " LocalizedDisplayName = 'Retired- $RetiringApp ' "
85- $RetiringAppWMI .SetIsExpired ( $true ) | Out-Null
88+ if (! $RetiringApp.IsExpired )
89+ {
90+ Suspend-CMApplication - Name " $RetiringAppName "
8691 Write-Host " Set status to Retired."
87- } else {
92+ }
93+ else
94+ {
8895 Write-Host " Status was already set to Retired."
8996 }
9097
0 commit comments