Skip to content

Instantly share code, notes, and snippets.

@HarmJ0y
Created September 5, 2017 02:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save HarmJ0y/43f59722565de09670be6b541935562b to your computer and use it in GitHub Desktop.
Save HarmJ0y/43f59722565de09670be6b541935562b to your computer and use it in GitHub Desktop.
OU_edit_metadata.ps1
# specify the GPO we're enumerating
$OUName = "TestOU1_policy"
# enumerate the last time the GPO was changed, based on the replication metadata of the 'versionNumber' property
$LastGPOChange = ([datetime](Get-DomainObjectAttributeHistory $OUName -Properties versionNumber | Select-Object -ExpandProperty LastOriginatingChange)).ToUniversalTime()
# grab the SYSVOL path for this particular GPO
$Path = Get-DomainObject $OUName | Select-Object -ExpandProperty gpcfilesyspath
# enumerate all files in the GPO edited +/- 20 seconds from the 'versionNumber' modification time
Get-ChildItem $Path -Recurse -Exclude 'GPT.ini' | ? {
($_.LastWriteTimeUtc -gt $LastGPOChange.AddSeconds(-20)) -and ($_.LastWriteTimeUtc -lt $LastGPOChange.AddSeconds(20))
} | Sort-Object -Property LastWriteTime -Descending
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment