Script Repository

Delete computer from SCCM server

February 18, 2021

The script deletes a computer from a System Center Configuration Manager (SCCM) Server. You can add it to your business rules, custom commands and scheduled tasks with the help of the Run a program or PowerShell script action.


  • $serverName - Specifies the SCCM Server name.
  • $siteCode - Specifies the SCCM Site Code.
  • $computerName - Specifies the computer name. You can use value references (e.g. %cn%) to insert the computer name. When the script is executed, the value references will be replaced with property values of the AD object on which the script is executed.
Edit Remove
$serverName = "" # TODO: modify me
$siteCode = "MyCode" # TODO: modify me
$computerName = "%cn%" # TODO: modify me

# Get Resource ID
$computer = Get-WmiObject -ComputerName $serverName -Namespace "Root\SMS\Site_$($siteCode)" -Class 'SMS_R_SYSTEM' -Filter "Name='$computerName'"

if ($computer.ResourceId -eq $NULL)
    $Context.LogMessage("The computer '$computername' has not been found in SCCM.", "Warning") # TODO: modify me

# Delete computer account
    $Context.LogMessage("Computer '$computerName' successfully deleted", "Information") # TODO: modify me
    $Context.LogMessage("Could not delete '$computerName'. Error: " + $_.Exception.Message, "Error") # TODO: modify me

Comments ( 0 )
No results found.
Leave a comment