≡ Menu

Reset and purge existing policies in SCCM using Powershell

The powershell script discussed in this article will help you reset and purge the policies on a SCCM client remotely using PowerShell.

SCCM(System Centre Configuration Manager) has variety of WMI classes and one of them is SMS_Client. This class helps you querying the machine policy remotely as well as reset and purge the existing policies.

You can check http://msdn.microsoft.com/en-us/library/cc146352.aspx for various methods available in this class. The script I am going to discuss below relies on ResetPolicy method to reset and purge the policies.

The script takes two arguments. 1) ComputerName 2) Purge. You can pass one or more computers(cama separated) to the ComputerName parameter. When this parameter is not specified it executes against local computer. The Purge argument is a switch type parameter. When it is used, the policy data will be purged. When not specified the reset policy will get executed with argument 1 which means full download of existing policy.

[string[]]$ComputerName = $env:ComputerName,            
[switch]$Purge = 0            

if($Purge) {            
 $Gflag = 1            
} else {            
 $Gflag = 0            

foreach($Computer in $ComputerName) {            
 $client = Get-WMIObject -Class SMS_Client -Namespace root\ccm -ComputerName $Computer            
 $returnval = $Client.ResetPolicy($Gflag)            
 if($returnvalue) {            
 Write-Warning "Error occurred while resetting/purging the policy on $Computer"            
 } else {            
 Write-Host "Purge/Reset successful on $Computer"            

I learned this from one of the contributor in “Hyderabad Powershell User Group” FB group. I am not an expert in SCCM but given that use case of this seems very high, I thought of converting it to a post.

Since I haven’t tried this script practically, I STRONGLY request you to try in a lab environment to see if it is giving desired results. Use at your own risk.

{ 5 comments… add one }
  • Gerry May 3, 2016, 11:39 pm

    The namespace you are using in your script above is incorrect. Probably a typo, but should -Namespace root\ccm

  • Levi April 16, 2018, 8:21 pm

    Or use a one-liner:
    Invoke-WMIMethod -Namespace root\ccm -Class SMS_Client -Name ResetPolicy -ArgumentList “1” -Computername “NAME”

    • Wintel Rocks April 18, 2018, 8:31 pm

      Yes that works for adhoc requirements. If you want something that works for multiple computers with error handling then the script will help.

  • Jon July 4, 2019, 2:15 am

    This doesn’t work in current version. Instead, the $client line should read:

    $client = Get-WMIObject -Class SMS_Client -Namespace root\ccm -ComputerName $Computer -List

    • Wintel Rocks July 9, 2019, 4:55 am

      Hi Jon,

      what is the problem you faced with the code in the post? The only difference I noticed is usage of -List parameter at the end of Get-WMIObject cmdlet which doesn’t add any value. Please help us understand so we can update the post accordingly.

Leave a Comment