From 4803d3e18338148e1a3be950773c1c3478513fdc Mon Sep 17 00:00:00 2001 From: Przemyslaw Klys Date: Sun, 24 Oct 2021 14:51:19 +0200 Subject: [PATCH] Improvements --- Private/Get-GPOZaurrLinkInheritance.ps1 | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/Private/Get-GPOZaurrLinkInheritance.ps1 b/Private/Get-GPOZaurrLinkInheritance.ps1 index 5934c35..e5e639b 100644 --- a/Private/Get-GPOZaurrLinkInheritance.ps1 +++ b/Private/Get-GPOZaurrLinkInheritance.ps1 @@ -31,13 +31,13 @@ function Get-GPOZaurrLinkInheritance { Parameter description .PARAMETER Forest - Parameter description + Target different Forest, by default current forest is used .PARAMETER ExcludeDomains - Parameter description + Exclude domain from search, by default whole forest is scanned .PARAMETER IncludeDomains - Parameter description + Include only specific domains, by default whole forest is scanned .PARAMETER ExtendedForestInformation Parameter description @@ -123,9 +123,13 @@ function Get-GPOZaurrLinkInheritance { # While initially we used $ForestInformation.Domains but the thing is GPOs can be linked to other domains so we need to get them all so we can use cache of it later on even if we're processing just one domain # That's why we use $ForestInformation.Forest.Domains instead foreach ($Domain in $ForestInformation.Forest.Domains) { - $QueryServer = $ForestInformation['QueryServers'][$Domain]['HostName'][0] - Get-GPO -All -DomainName $Domain -Server $QueryServer | ForEach-Object { - $GPOCache["$Domain$($_.ID.Guid)"] = $_ + if ($ForestInformation['QueryServers'][$Domain]) { + $QueryServer = $ForestInformation['QueryServers'][$Domain]['HostName'][0] + Get-GPO -All -DomainName $Domain -Server $QueryServer | ForEach-Object { + $GPOCache["$Domain$($_.ID.Guid)"] = $_ + } + } else { + Write-Warning -Message "Get-GPOZaurrLinkInheritance - Couldn't get query server for $Domain. Skipped." } } }