Get-GPOVersion.ps1
<#PSScriptInfo .VERSION 1.1 .GUID 0c8f085c-0088-4ad9-a79a-ee460ff460db .AUTHOR mikejwhat .COMPANYNAME .COPYRIGHT .TAGS .LICENSEURI .PROJECTURI https://github.com/mikejwhat/ActiveDirectoryTools .ICONURI .EXTERNALMODULEDEPENDENCIES .REQUIREDSCRIPTS .EXTERNALSCRIPTDEPENDENCIES .RELEASENOTES #> <# .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. #> using module ActiveDirectory using module GroupPolicy <# .SYNOPSIS Gathers the Active Directory and SYSVOL version numbers of Group Policy Objects. .INPUTS Microsoft.ActiveDirectory.Management.ADComputer, System.String .OUTPUTS System.Management.Automation.PSCustomObject .EXAMPLE Get-GPOVersion 'DC01' .EXAMPLE 'DC01' | Get-GPOVersion .EXAMPLE Get-ADComputer 'DC01' | Get-GPOVersion .EXAMPLE Get-ADComputer -Filter * -SearchBase "$((Get-ADDomain).DomainControllersContainer)" | Get-GPOVersion .EXAMPLE Get-GPOVersion 'DC01','DC02','DC03' | Out-GridView .EXAMPLE Get-ADComputer -Filter * | where name -like DC* | Export-Csv -NoTypeInformation $env:temp\GPOs.csv #> 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 } $cCount = 0 foreach ($c in $ComputerName) { $cCount++ 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 |