PowerShell script for SCCM cleanup activities

 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:

Deletes inactive client records older than 90 days
Deletes expired and superseded software updates
Deletes unused software update groups
Deletes orphaned task sequences

You can customize this script to include additional cleanup tasks as needed. Note that this script assumes you have the SCCM PowerShell module installed and that you have the necessary permissions to perform the cleanup tasks.

No comments:

Post a Comment