Check if Group Policy is Out of Date with PowerShell

This PowerShell script will check the registry for the last time the Group Policy ran, calculate the current date and compare to a set value (30 Days). It will the result is greater than the set value it will return $true or $false.

# Get StartTimeHi Int32 value
$startTimeHi = (Get-ItemProperty -Path "Registry::HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Group Policy\State\Machine\Extension-List\{00000000-0000-0000-0000-000000000000}").startTimeHi
# Get StartTimeLo Int32 value
$startTimeLo = (Get-ItemProperty -Path "Registry::HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Group Policy\State\Machine\Extension-List\{00000000-0000-0000-0000-000000000000}").startTimeLo
# Convert from FileTime
$gpDateTime = [datetime]::FromFileTime(([Int64] $startTimeHi -shl 32) -bor $startTimeLo)
$lastModifiedDate = (Get-Item "$env:SystemRoot\System32\GroupPolicy\Machine\Registry.pol").LastWriteTime

if (($gpDateTime -lt (Get-Date).AddDays(-30)) -or ($lastModifiedDate -lt (Get-Date).AddDays(-30))) {Return $true} else {$false}

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.