Aracılığıyla paylaş


Removing boundary groups that don't have a site system defined in ConfigMgr with PowerShell

A customer of mine had the question: How can we script the removal of boundary groups that don't have a site system defined in ConfigMgr 2012 R2?

PowerShell to the rescue!

We can simply use the SMS_BoundaryGroup Class in WMI, like so:

 

$BGID = (get-wmiobject -class sms_boundarygroup -Namespace root\sms\site_C12 -Filter "SiteSystemCount = '0'").GroupID

 

This will grab all of the boundary groups in WMI, that have a site system count of 0.

Then we can use the Remove-CMBoundaryGroup cmdlet within a function, to remove the

boundarygroup(s):

 

Function RemoveBoundaryGroups {

 

  Foreach ($BGID in $BGID)

  {

    Remove-CMBoundaryGroup -ID "$BGID" -Force

    Write-Host Removing Boundary Group with ID number: $BGID

  }

 

Here is a visual of my console, that shows I have two boundary groups with site systems defined:

 

Here is what things look like in WMI for my test lab, that shows I have 72 Boundary Groups:

 

The final results when the script is ran. As expected, 70 Boundary Groups were removed:

 

Remove-CMBoundaryGroup 

https://technet.microsoft.com/en-us/library/jj822002(v=sc.20).aspx

 

I've attached a sample script that will need to be edited to fit your environment.

Disclaimer: The information on this site is provided "AS IS" with no warranties, confers no rights, and is not supported by the authors or Microsoft Corporation. Use of included script samples are subject to the terms specified
in the
Terms of Use .

RemoveBoundaryGroup.zip