-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGet-GPOApply.ps1
67 lines (48 loc) · 1.95 KB
/
Get-GPOApply.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<#PSScriptInfo
.VERSION 1.0
.GUID 28947f3f-5121-4bd9-850b-d07e73d83907
.AUTHOR Anthony Yates
.COMPANYNAME Airdesk Services
.COPYRIGHT 2024 Anthony Yates
.TAGS Active Directory
.LICENSEURI https://github.com/Air-Git/ad-remediation/blob/main/LICENSE
.PROJECTURI https://github.com/Air-Git/ad-remediation/tree/main
.ICONURI
.EXTERNALMODULEDEPENDENCIES Group Policy
.REQUIREDSCRIPTS None
.EXTERNALSCRIPTDEPENDENCIES None
.RELEASENOTES
.PRIVATEDATA
#>
<#
.DESCRIPTION
A script to show who has GPO Apply permissions for each GPO.
The aim is to spot GPOs that apply to either very few, or no accounts, or only to deleted accounts (unknownSID).
Because a GPO permission may have multiple trustees, each trustee is shown on a separate line of the report.
The name of the output report is hard-coded in the script. Edit it before running.
#>
$fileDate = Get-Date -Format ddMMyy
$Gpos = Get-GPO -All | Where-Object { $_.GpoStatus -ne "AllSettingsDisabled" } | Sort-Object DisplayName
$Gpos | ForEach-Object {
$GpoName = $_.DisplayName
$GpoStatus = $_.GpoStatus
[xml]$GpoReport = Get-GPOReport -Guid $_.Id -ReportType Xml
$links = $GpoReport.GPO.LinksTo.SOMPath
$apply = Get-GPPermission -Guid $_.Id -All | Where-Object { $_.Permission -eq 'GpoApply' }
$AU = $false
$onlyUnknownSID = $true
$apply | ForEach-Object {
if ($_.Trustee.Name -eq 'Authenticated Users' -or $_.Trustee.Name -eq 'Domain Computers') { $AU = $true }
if ($null -ne $_.Trustee.Name) { $onlyUnknownSID = $false }
}
$apply | ForEach-Object {
[pscustomobject]@{
'Name' = $GpoName
'Status' = $GpoStatus
'Links' = $links -join '; '
'Trustee' = $_.Trustee.Name
'All' = $AU
'Only Unknown' = $onlyUnknownSID
}
}
} | Export-Csv "C:\Temp\GPOApply_$fileDate.Csv" -NoTypeInformation