Last active
August 3, 2018 09:02
-
-
Save DarkAllien/988687d3f516a7c83704ee368f869a3d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| [CmdletBinding()] | |
| Param( | |
| [Parameter(Mandatory = $True, Position = 1)] | |
| [string] $ApplicationName | |
| ) | |
| Try { | |
| Import-Module "$($ENV:SMS_ADMIN_UI_PATH)\..\ConfigurationManager.psd1" -ErrorAction "Stop" | |
| } | |
| Catch { | |
| Write-host -Message 'Importing SCCM PSH module - Failed!' | |
| } | |
| # Get the CMSITE SiteCode and change connection context | |
| Try { | |
| $SiteCode = (Get-PSDrive -PSProvider CMSITE).Name | |
| } | |
| Catch { | |
| Write-host -Message 'Get PS drive - Failed!' | |
| } | |
| # Change the connection context | |
| Try { | |
| Set-Location "$($SiteCode):\" | |
| } | |
| Catch { | |
| Write-host -Message 'Set location to Site Drive - Failed!' | |
| } | |
| #runing from site server | |
| write-host $MyInvocation.MyCommand.Name | |
| write-host "Removing old revisions from:"$ApplicationName | |
| $flag = $true | |
| $cmApp = Get-CMApplication -name $ApplicationName | |
| $cmAppRevision = $cmApp | Get-CMApplicationRevisionHistory | |
| for ($i = 0; $i -lt $cmAppRevision.Count - 1; $i++) { | |
| write-host "Removing revision: "$cmAppRevision[$i].civersion | |
| Remove-CMApplicationRevisionHistory -Id $cmAppRevision[$i].ci_id -Revision $cmAppRevision[$i].civersion -force -Verbose | |
| $flag = $false | |
| } | |
| if ($flag) {write-host "No old revisions to remove!"} | |
| Write-host "Finished!" | |
| Read-Host -Prompt "Press ENTER to exit" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment