IN_GPO
Summary
Description
Identification
PowerShell
function Find-IN_GPO {
[CmdletBinding()]
param (
[string]$GPOGuid = $null, # Specific GPO GUID to scan
[string]$OutputPath = "GPOScripts.csv" # Output CSV path
)
# Load GroupPolicy module if not already loaded
if (-not (Get-Module -Name GroupPolicy)) {
Write-Host "Attempting to load GroupPolicy module..."
try {
Import-Module GroupPolicy
Write-Host "GroupPolicy module loaded successfully."
}
catch {
Write-Error "Failed to load GroupPolicy module. Please ensure RSAT-GroupPolicy is installed."
return
}
}
function Get-GPOScriptDetails {
param ([Microsoft.GroupPolicy.Gpo]$GPO)
$results = @()
try {
[xml]$report = Get-GPOReport -Guid $GPO.Id -ReportType Xml
foreach ($context in @("Computer", "User")) {
$data = $report.GPO.$context.ExtensionData | Where-Object { $_.Name -eq 'Scripts' }
if ($data) {
foreach ($script in $data.Extension.Script) {
$results += [PSCustomObject]@{
GPOName = $GPO.DisplayName
GPOID = $GPO.Id
ScriptType = $script.Type
ScriptPath = $script.Command
Parameters = $script.Parameters
Context = $context
LastModified = $GPO.ModificationTime
}
}
}
}
}
catch {
Write-Warning "Error processing GPO '$($GPO.DisplayName)': $_"
}
return $results
}
if ($GPOGuid) {
Write-Host "Scanning specific GPO with GUID: $GPOGuid"
try {
$gpo = Get-GPO -Guid $GPOGuid -ErrorAction Stop
$allScripts = Get-GPOScriptDetails -GPO $gpo
}
catch {
Write-Error "Failed to retrieve GPO with GUID $GPOGuid: $($_.Exception.Message)"
return
}
}
else {
Write-Host "Scanning all GPOs in the domain..."
try {
$allGPOs = Get-GPO -All -ErrorAction Stop
$allScripts = $allGPOs | ForEach-Object { Get-GPOScriptDetails -GPO $_ }
}
catch {
Write-Error "Failed to enumerate GPOs: $($_.Exception.Message)"
return
}
}
if ($allScripts.Count -gt 0) {
Write-Host "Found $($allScripts.Count) script entry(ies) in GPO(s)."
try {
$allScripts | Export-Csv -Path $OutputPath -NoTypeInformation -Encoding UTF8 -ErrorAction Stop
Write-Output "Results exported successfully to '$OutputPath'"
}
catch {
Write-Error "Failed to export results to CSV file '$OutputPath': $($_.Exception.Message)"
}
}
else {
Write-Output "No scripts found in GPO(s)."
}
}
Exploitation
Mitigation

Detection
Event ID
Description
Fields/Attributes
References
References
Last updated
Was this helpful?