mirror of
https://github.com/EvotecIT/GPOZaurr.git
synced 2026-08-12 11:47:08 +00:00
68 lines
3.4 KiB
PowerShell
68 lines
3.4 KiB
PowerShell
function Get-GPOZaurrInheritance {
|
|
[cmdletBinding()]
|
|
param(
|
|
[switch] $IncludeBlockedObjects,
|
|
[switch] $OnlyBlockedInheritance,
|
|
|
|
[alias('ForestName')][string] $Forest,
|
|
[string[]] $ExcludeDomains,
|
|
[alias('Domain', 'Domains')][string[]] $IncludeDomains,
|
|
[System.Collections.IDictionary] $ExtendedForestInformation
|
|
)
|
|
Begin {
|
|
$ForestInformation = Get-WinADForestDetails -Extended -Forest $Forest -IncludeDomains $IncludeDomains -ExcludeDomains $ExcludeDomains -ExtendedForestInformation $ExtendedForestInformation
|
|
}
|
|
Process {
|
|
foreach ($Domain in $ForestInformation.Domains) {
|
|
$OrganizationalUnits = Get-ADOrganizationalUnit -Filter * -Properties gpOptions, canonicalName -Server $ForestInformation['QueryServers'][$Domain]['HostName'][0]
|
|
foreach ($OU in $OrganizationalUnits) {
|
|
$InheritanceInformation = [Ordered] @{
|
|
CanonicalName = $OU.canonicalName
|
|
BlockedInheritance = if ($OU.gpOptions -eq 1) { $true } else { $false }
|
|
}
|
|
if (-not $IncludeBlockedObjects) {
|
|
if ($OnlyBlockedInheritance) {
|
|
if ($InheritanceInformation.BlockedInheritance -eq $true) {
|
|
[PSCustomObject] $InheritanceInformation
|
|
}
|
|
} else {
|
|
[PSCustomObject] $InheritanceInformation
|
|
}
|
|
} else {
|
|
if ($InheritanceInformation) {
|
|
if ($InheritanceInformation.BlockedInheritance -eq $true) {
|
|
$InheritanceInformation['UsersCount'] = $null
|
|
$InheritanceInformation['ComputersCount'] = $null
|
|
[Array] $InheritanceInformation['Users'] = (Get-ADUser -SearchBase $OU.DistinguishedName -Server $ForestInformation['QueryServers'][$Domain]['HostName'][0] -Filter *).SamAccountName
|
|
[Array] $InheritanceInformation['Computers'] = (Get-ADComputer -SearchBase $OU.DistinguishedName -Server $ForestInformation['QueryServers'][$Domain]['HostName'][0] -Filter *).SamAccountName
|
|
$InheritanceInformation['UsersCount'] = $InheritanceInformation['Users'].Count
|
|
$InheritanceInformation['ComputersCount'] = $InheritanceInformation['Computers'].Count
|
|
} else {
|
|
$InheritanceInformation['UsersCount'] = $null
|
|
$InheritanceInformation['ComputersCount'] = $null
|
|
$InheritanceInformation['Users'] = $null
|
|
$InheritanceInformation['Computers'] = $null
|
|
}
|
|
}
|
|
if ($OnlyBlockedInheritance) {
|
|
if ($InheritanceInformation.BlockedInheritance -eq $true) {
|
|
[PSCustomObject] $InheritanceInformation
|
|
}
|
|
} else {
|
|
[PSCustomObject] $InheritanceInformation
|
|
}
|
|
}
|
|
$InheritanceInformation['DistinguishedName'] = $OU.DistinguishedName
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
<#
|
|
|
|
$OrganizationalUnits = Get-ADOrganizationalUnit -Filter *
|
|
$Output = foreach ($OU in $OrganizationalUnits) {
|
|
Get-GPInheritance -Target $OU.DistinguishedName
|
|
}
|
|
$Output | Format-Table
|
|
#> |