Repository navigation
Expand file tree
/
Copy pathGet-GPOLinks.ps1
More file actions
81 lines (69 loc) · 2.27 KB
/
Copy pathGet-GPOLinks.ps1
File metadata and controls
81 lines (69 loc) · 2.27 KB
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
<#
.SYNOPSIS
Listet alle GPOs mit ihren Verknuepfungen auf und findet unverknuepfte.
.DESCRIPTION
Liest je Gruppenrichtlinie den XML-Report und zieht daraus die
Verknuepfungen auf Standorte, Domaenen und OUs samt Status (aktiviert,
erzwungen). Mit -UnlinkedOnly bleiben nur GPOs uebrig, die nirgends
verknuepft sind - typischerweise Altlasten, die bei jeder
Richtlinienverarbeitung trotzdem ausgewertet werden koennen.
.NOTES
Benoetigt das Modul GroupPolicy.
#>
# # Alle GPOs inkl. Links
# Get-GPOLinks
# # Nur eine bestimmte GPO (Name oder GUID, auch mit Wildcard)
# Get-GPOLinks -GPOName "Default*"
# # Nur unverknüpfte GPOs
# Get-GPOLinks -UnlinkedOnly
function Get-GPOLinks {
[CmdletBinding()]
param(
[string]$GPOName,
[switch]$UnlinkedOnly
)
$allGPOs = if ($GPOName) {
# Direkt filtern auf Name oder GUID, damit wir nicht alle durchlaufen müssen
Get-GPO -All | Where-Object {
$_.DisplayName -like $GPOName -or $_.Id.Guid -like $GPOName
}
}
else {
Get-GPO -All
}
$result = foreach ($gpo in $allGPOs) {
try {
$xmlReport = Get-GPOReport -Guid $gpo.Id -ReportType Xml
[xml]$xmlContent = $xmlReport
}
catch {
Write-Warning "Fehler beim Einlesen von GPO $($gpo.DisplayName) ($($gpo.Id)): $($_.Exception.Message)"
continue
}
$links = $xmlContent.GPO.LinksTo
if ($links) {
foreach ($link in $links) {
[PSCustomObject]@{
DisplayName = $xmlContent.GPO.Name
GUID = $xmlContent.GPO.Identifier.Identifier.InnerText
OU = $link.SOMPath
Enabled = $link.Enabled
Enforced = $link.NoOverride
}
}
}
else {
[PSCustomObject]@{
DisplayName = $xmlContent.GPO.Name
GUID = $xmlContent.GPO.Identifier.Identifier.InnerText
OU = $null
Enabled = $false
Enforced = $false
}
}
}
if ($UnlinkedOnly) {
$result = $result | Where-Object { -not $_.OU }
}
$result
}