Here's a basic PowerShell script for performing SCCM cleanup activity

Here's a basic PowerShell script for performing SCCM cleanup activity:


 # Define SCCM server name and site code

$SCCMServerName = "SCCMServer"

$SiteCode = "ABC"


# Connect to SCCM server using the SCCM cmdlet

Import-Module ($Env:SMS_ADMIN_UI_PATH.Substring(0,$Env:SMS_ADMIN_UI_PATH.Length-5) + '\ConfigurationManager.psd1')

Set-Location "$($SiteCode):"


# Clean up expired updates

$ExpiredUpdates = Get-CMUpdate -Expired

ForEach ($Update in $ExpiredUpdates) {

    Write-Host "Deleting expired update: $($Update.LocalizedDisplayName)"

    Remove-CMUpdate -Update $Update

}


# Clean up old task sequences

$OldTaskSequences = Get-CMTaskSequence | Where-Object {$_.LastModifiedDate -lt (Get-Date).AddMonths(-6)}

ForEach ($TaskSequence in $OldTaskSequences) {

    Write-Host "Deleting old task sequence: $($TaskSequence.Name)"

    Remove-CMTaskSequence -TaskSequencePackage $TaskSequence

}


# Clean up orphaned content

Start-CMContentLibraryCleanup -DeleteOrphanedContent



This script connects to the SCCM server, cleans up expired updates, old task sequences, and orphaned content. You can customize it further to include other cleanup activities as needed. Please note that this script is only meant to serve as an example and you should test and modify it as appropriate for your specific environment before running it in production.

No comments:

Post a Comment