Monday, August 8, 2016

Count number of GPOs using Powershell

Hi guys,

today I want to show you, how to count your GPOs. I also want to show you how to create filters that could be useful...

This script will show you the number of all GPOs in your domain:

$GPOCOunt = ((Get-GPO -All).count)
Write-Host "Number of GPOs: $GPOCOunt"

If you have a naming convention in place, you could filter and count these GPOs.
For example you name GPOs based on location shortcuts like US.
So lets get all GPOs starting with "US":

# Get all GPOs that are starts with US
$GPOCOuntUS = ((Get-GPO -All | where{($_.displayname –like “US*”)}))
# Count them
$GPOCOuntUS2 = $GPOCOuntUS.count
# Write output
Write-Host "Number of GPOs for US: $GPOCOuntUS2"

Another good filter (almost all use it I think...) is test
So lets get all GPOs that include the word test:
$GPOCOuntTest = ((Get-GPO -All | where{($_.displayname –like “*test*”)}))
$GPOCOuntTest2 = $GPOCOuntTest.count
Write-Host "Number of your TEST GPOs: $GPOCOuntTest2"

No comments:

Post a Comment