From d6ae5bfc7be791ff5480ca7f1d288e372918d2ed Mon Sep 17 00:00:00 2001 From: Przemyslaw Klys Date: Thu, 18 Jun 2020 14:53:36 +0200 Subject: [PATCH] Update --- Public/Get-GPOZaurrLink.ps1 | 34 ++++++++++++++++++++++++++++------ README.md | 5 +++++ 2 files changed, 33 insertions(+), 6 deletions(-) diff --git a/Public/Get-GPOZaurrLink.ps1 b/Public/Get-GPOZaurrLink.ps1 index d21d5fb..0b6fbc4 100644 --- a/Public/Get-GPOZaurrLink.ps1 +++ b/Public/Get-GPOZaurrLink.ps1 @@ -14,6 +14,11 @@ [parameter(ParameterSetName = 'Linked')] [switch] $Limited, + [parameter(ParameterSetName = 'Filter')] + [parameter(ParameterSetName = 'ADObject')] + [parameter(ParameterSetName = 'Linked')] + [switch] $SkipDuplicates, + [parameter(ParameterSetName = 'Filter')] [parameter(ParameterSetName = 'ADObject')] [parameter(ParameterSetName = 'Linked')] @@ -40,6 +45,7 @@ [System.Collections.IDictionary] $ExtendedForestInformation ) Begin { + $CacheReturnedGPOs = [ordered] @{} $ForestInformation = Get-WinADForestDetails -Extended -Forest $Forest -IncludeDomains $IncludeDomains -ExcludeDomains $ExcludeDomains -ExtendedForestInformation $ExtendedForestInformation if (-not $GPOCache -and -not $Limited) { $GPOCache = @{ } @@ -71,7 +77,8 @@ #} $Splat['Filter'] = "(objectClass -eq 'organizationalUnit')" $Splat['SearchBase'] = $SearchBase - Get-ADObject @Splat | ForEach-Object -Process { + $ADObjectGPO = Get-ADObject @Splat + foreach ($_ in $ADObjectGPO) { Get-PrivGPOZaurrLink -Object $_ -Limited:$Limited.IsPresent -GPOCache $GPOCache } } @@ -83,7 +90,8 @@ # } $Splat['Filter'] = "objectClass -eq 'domainDNS'" $Splat['SearchBase'] = $SearchBase - Get-ADObject @Splat | ForEach-Object -Process { + $ADObjectGPO = Get-ADObject @Splat + foreach ($_ in $ADObjectGPO) { Get-PrivGPOZaurrLink -Object $_ -Limited:$Limited.IsPresent -GPOCache $GPOCache } } @@ -97,7 +105,8 @@ #} $Splat['Filter'] = "(objectClass -eq 'site')" $Splat['SearchBase'] = $SearchBase - Get-ADObject @Splat | ForEach-Object -Process { + $ADObjectGPO = Get-ADObject @Splat + foreach ($_ in $ADObjectGPO) { Get-PrivGPOZaurrLink -Object $_ -Limited:$Limited.IsPresent -GPOCache $GPOCache } } @@ -110,7 +119,8 @@ #} $Splat['Filter'] = "(objectClass -eq 'organizationalUnit')" $Splat['SearchBase'] = $SearchBase - Get-ADObject @Splat | ForEach-Object -Process { + $ADObjectGPO = Get-ADObject @Splat + foreach ($_ in $ADObjectGPO) { if ($_.DistinguishedName -eq $ForestInformation['DomainsExtended'][$Domain]['DistinguishedName']) { # other skips Domain Root } elseif ($_.DistinguishedName -eq $ForestInformation['DomainsExtended'][$Domain]['DomainControllersContainer']) { @@ -143,8 +153,20 @@ } try { - Get-ADObject @Splat | ForEach-Object { - Get-PrivGPOZaurrLink -Object $_ -Limited:$Limited.IsPresent -GPOCache $GPOCache + $ADObjectGPO = Get-ADObject @Splat + foreach ($_ in $ADObjectGPO) { + $OutputGPOs = Get-PrivGPOZaurrLink -Object $_ -Limited:$Limited.IsPresent -GPOCache $GPOCache + foreach ($OutputGPO in $OutputGPOs) { + if (-not $SkipDuplicates) { + $OutputGPO + } else { + $UniqueGuid = -join ($OutputGPO.DomainName, $OutputGPO.Guid) + if (-not $CacheReturnedGPOs[$UniqueGuid]) { + $CacheReturnedGPOs[$UniqueGuid] = $OutputGPO + $OutputGPO + } + } + } } } catch { Write-Warning "Get-GPOZaurrLink - Processing error $($_.Exception.Message)" diff --git a/README.md b/README.md index 06d71ac..d73e197 100644 --- a/README.md +++ b/README.md @@ -39,6 +39,11 @@ That's it. Whenever there's a new version, you run the command, and you can enjo ## Changelog +- 0.0.40 - 18.06.2020 + - Fix for error `Get-GPOZaurrLink` - same issue as described on my [earlier blog - Get-ADObject : The server has returned the following error: invalid enumeration context.](https://evotec.xyz/get-adobject-the-server-has-returned-the-following-error-invalid-enumeration-context/). + - `WARNING: Get-GPOZaurrLink - Processing error The server has returned the following error: invalid enumeration context.` + - `WARNING: Get-GPOZaurrLink - Processing error A referral was returned from the server` + - Added `SkipDuplicates` for `Get-GPOZaurrLink` - 0.0.39 - 17.06.2020 - Updates to `Invoke-GPOZaurrPermission` with new parameter `LimitAdministrativeGroupsToDomain` - This will get administrative based on IncludeDomains if given. It means that if GPO has Domain admins added from multiple domains it will only find one, and remove all other Domain Admins (if working with Domain Admins that is)