≡ 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\cms -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.

{ 1 comment… 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

Leave a Comment