Created
May 20, 2019 19:49
-
-
Save realslacker/6636c0f25fc24bb605a03b11ecd03142 to your computer and use it in GitHub Desktop.
Get all Group Policy Objects with scripts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Import-Module GroupPolicy -ErrorAction Stop | |
Get-GPO -All | | |
ForEach-Object { Write-Host ( 'Processing GPO ''{0}''...' -f $_.DisplayName ); $_ } -pv 'GPO' | | |
Get-GPOReport -ReportType Xml | | |
ForEach-Object { [xml]$_ } | | |
foreach-Object { | |
$_.GPO.User.ExtensionData | | |
Where-Object { $_.Name -eq 'Scripts' } | | |
ForEach-Object { | |
New-Object -TypeName PSCustomObject -Property @{ | |
GPOName = $GPO.DisplayName | |
ID = $GPO.ID | |
State = $GPO.GpoStatus | |
AppliesTo = 'User' | |
Type = $_.Type | |
Script = $_.Command | |
} | |
} | |
$_.GPO.Computer.ExtensionData | | |
Where-Object { $_.Name -eq 'Scripts' } | | |
ForEach-Object { | |
New-Object -TypeName PSCustomObject -Property @{ | |
GPOName = $GPO.DisplayName | |
ID = $GPO.ID | |
State = $GPO.GpoStatus | |
AppliesTo = 'Computer' | |
Type = $_.Type | |
Script = $_.Command | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment