PowerShell script for SCCM cleanup activities
# Connect to the SCCM server
$SiteServer = "SCCMServerName" $SiteCode = "SiteCode" $SiteServerConnection = Connect-SiteServer -SiteServer $SiteServer -SiteCode $SiteCode # Delete inactive client records older than 90 days $InactiveClients = Get-CMDevice -InactiveDays 90 ForEach ($InactiveClient in $InactiveClients) { Remove-CMDevice -InputObject $InactiveClient -Force } # Delete expired and superseded software updates $ExpiredUpdates = Get-CMSoftwareUpdate -Expired $SupersededUpdates = Get-CMSoftwareUpdate -Superseded ForEach ($Update in ($ExpiredUpdates + $SupersededUpdates)) { Remove-CMSoftwareUpdate -InputObject $Update -Force } # Delete unused software update groups $UnusedUpdateGroups = Get-CMSoftwareUpdateGroup | Where-Object { $_.UpdateCount -eq 0 } ForEach ($UpdateGroup in $UnusedUpdateGroups) { Remove-CMSoftwareUpdateGroup -InputObject $UpdateGroup -Force } # Delete orphaned task sequences $OrphanedTaskSequences = Get-CMTaskSequence | Where-Object { $_.Package -eq $null } ForEach ($TaskSequence in $OrphanedTaskSequences) { Remove-CMTaskSequence -InputObject $TaskSequence -Force } # Disconnect from the SCCM server Disconnect-SiteServer -SiteServerConnection $SiteServerConnection
This script performs the following SCCM cleanup tasks:
This script performs the following SCCM cleanup tasks:
No comments:
Post a Comment