Get-GPOVersion.ps1

<#PSScriptInfo

.DESCRIPTION
 This cmdlet will gather the Active Directory and SYSVOL version numbers of every Group Policy Object (GPO) in the domain. This enables you to confirm GPO consistency across Domain Controllers.

.VERSION 1.5.0

.GUID a65878f9-d099-47ed-8891-c32bde886f52

.AUTHOR mikejwhat

.COMPANYNAME

.COPYRIGHT

.TAGS

.LICENSEURI

.PROJECTURI https://github.com/mikejwhat/Get-GPOVersion

.ICONURI

.EXTERNALMODULEDEPENDENCIES ActiveDirectory,GroupPolicy

.REQUIREDSCRIPTS

.EXTERNALSCRIPTDEPENDENCIES

.RELEASENOTES

.PRIVATEDATA

#>


#Requires -Module ActiveDirectory
#Requires -Module GroupPolicy
function Get-GPOVersion {
   [CmdletBinding()]
   param(
       [Parameter (Mandatory=$true,
                   ValueFromPipeline=$true,
                   ValueFromPipelineByPropertyName=$true,
                   Position=0,
                   ParameterSetName='ComputerName')]
       [String[]]$ComputerName,
       [Parameter (Mandatory=$true,
                   ValueFromPipeline=$true,
                   ParameterSetName='InputObject')]
       [Microsoft.ActiveDirectory.Management.ADComputer[]]$InputObject
   )
   BEGIN {}
   PROCESS {
       if ($InputObject) {
           $ComputerName = $InputObject.Name
       }
       foreach ($c in $ComputerName) {
           Write-Verbose -Message ("{0} Querying domain controller `'$($c.toupper())`' for GPOs..." -f (Get-Date).TimeOfDay)
           try {
               $gpo = Get-GPO -Server $c -All -ErrorAction Stop
           }
           catch {
               Write-Warning "Could not retrieve GPOs from $c"
               continue
           }
           $gCount = 0
           foreach ($g in $gpo) {
               $gCount++
               Write-Verbose -Message ("{0} GPO `($($gCount) of $($gpo.count)`) `'$($g.Displayname.toupper())`'" -f (Get-Date).TimeOfDay) 
               [PSCustomObject]@{
                   DCName            = $c
                   GPODisplayName    = $g.DisplayName
                   ADUserVer         = $g.User.DSVersion
                   SYSVOLUserVer     = $g.User.SysvolVersion
                   ADComputerVer     = $g.Computer.DSVersion
                   SYSVOLComputerVer = $g.Computer.SysvolVersion
                   GPOId             = $g.Id
               }
           } # gpos foreach
       } # computername foreach
   } # process
   END {}
} # function