From 48246337871d41d900e10e3976d448b87d09f02b Mon Sep 17 00:00:00 2001 From: Przemyslaw Klys Date: Sat, 16 Sep 2023 09:34:20 +0200 Subject: [PATCH] Changed pipeline foreach into foreach for better/safer results --- Public/Get-GPOZaurrRedirect.ps1 | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/Public/Get-GPOZaurrRedirect.ps1 b/Public/Get-GPOZaurrRedirect.ps1 index 6007fc7..dd9f206 100644 --- a/Public/Get-GPOZaurrRedirect.ps1 +++ b/Public/Get-GPOZaurrRedirect.ps1 @@ -128,30 +128,31 @@ } Write-Verbose -Message "Get-GPOZaurrRedirect - Searching domain $Domain with filter $($Splat['Filter'])" - Get-ADObject @Splat -Properties DisplayName, Name, Created, Modified, ntSecurityDescriptor, gPCFileSysPath, gPCFunctionalityVersion, gPCWQLFilter, gPCMachineExtensionNames, Description, CanonicalName, DistinguishedName | ForEach-Object -Process { - $DomainCN = ConvertFrom-DistinguishedName -DistinguishedName $_.DistinguishedName -ToDomainCN - $GUID = $_.Name -replace '{' -replace '}' + $Objects = Get-ADObject @Splat -Properties DisplayName, Name, Created, Modified, ntSecurityDescriptor, gPCFileSysPath, gPCFunctionalityVersion, gPCWQLFilter, gPCMachineExtensionNames, Description, CanonicalName, DistinguishedName + foreach ($Object in $Objects) { + $DomainCN = ConvertFrom-DistinguishedName -DistinguishedName $Object.DistinguishedName -ToDomainCN + $GUID = $Object.Name -replace '{' -replace '}' if (($GUID).Length -ne 36) { - Write-Warning "Get-GPOZaurrRedirect - GPO GUID ($($($GUID.Replace("`n",' ')))) is incorrect. Skipping $($_.DisplayName) / Domain: $($DomainCN)" + Write-Warning "Get-GPOZaurrRedirect - GPO GUID ($($($GUID.Replace("`n",' ')))) is incorrect. Skipping $($Object.DisplayName) / Domain: $($DomainCN)" } else { - $Path = $_.gPCFileSysPath + $Path = $Object.gPCFileSysPath $ExpectedPath = "\\$($DomainCN)\SYSVOL\$($DomainCN)\Policies\{$($GUID)}" $Compare = if ($Path -eq $ExpectedPath) { $true } else { $false } [PSCustomObject]@{ - 'DisplayName' = $_.DisplayName + 'DisplayName' = $Object.DisplayName 'DomainName' = $DomainCN - 'Description' = $_.Description + 'Description' = $Object.Description 'IsCorrect' = $Compare 'GUID' = $GUID 'Path' = $Path 'ExpectedPath' = $ExpectedPath - #$Output['FunctionalityVersion'] = $_.gPCFunctionalityVersion - 'Created' = $_.Created - 'Modified' = $_.Modified - 'Owner' = $_.ntSecurityDescriptor.Owner - 'GPOCanonicalName' = $_.CanonicalName - 'GPODomainDistinguishedName' = ConvertFrom-DistinguishedName -DistinguishedName $_.DistinguishedName -ToDC - 'GPODistinguishedName' = $_.DistinguishedName + #$Output['FunctionalityVersion'] = $Object.gPCFunctionalityVersion + 'Created' = $Object.Created + 'Modified' = $Object.Modified + 'Owner' = $Object.ntSecurityDescriptor.Owner + 'GPOCanonicalName' = $Object.CanonicalName + 'GPODomainDistinguishedName' = ConvertFrom-DistinguishedName -DistinguishedName $Object.DistinguishedName -ToDC + 'GPODistinguishedName' = $Object.DistinguishedName } } }