Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Get all Group Policy Objects with scripts
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