From 1f4381680426e4c789a4ece836c82732ed60baf1 Mon Sep 17 00:00:00 2001 From: Przemyslaw Klys Date: Fri, 26 May 2023 13:08:51 +0200 Subject: [PATCH] Improve Remove-GPOZaurr LimitProcessing --- Public/Remove-GPOZaurr.ps1 | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/Public/Remove-GPOZaurr.ps1 b/Public/Remove-GPOZaurr.ps1 index 17fd2ad..6a6f966 100644 --- a/Public/Remove-GPOZaurr.ps1 +++ b/Public/Remove-GPOZaurr.ps1 @@ -22,11 +22,11 @@ $BackupFinalPath = $BackupPath } Write-Verbose "Remove-GPOZaurr - Backing up to $BackupFinalPath" - $null = New-Item -ItemType Directory -Path $BackupFinalPath -Force + $null = New-Item -ItemType Directory -Path $BackupFinalPath -Force -WhatIf:$false } else { $BackupRequired = $false } - $Count = 0 + $CountProcessedGPO = 0 } Process { $getGPOZaurrSplat = @{ @@ -39,6 +39,11 @@ } Get-GPOZaurr @getGPOZaurrSplat | ForEach-Object { + if ($LimitProcessing -ne 0 -and $CountProcessedGPO -ge $LimitProcessing) { + Write-Warning -Message "Remove-GPOZaurr - LimitProcessing ($CountProcessedGPO / $LimitProcessing) reached. Stopping processing" + break + } + $DeleteRequired = $false if ($Type -contains 'Empty') { @@ -89,10 +94,7 @@ Write-Warning "Remove-GPOZaurr - Removing GPO $($_.DisplayName) from $($_.DomainName) failed: $($_.Exception.Message)" } } - $Count++ - if ($LimitProcessing -eq $Count) { - break - } + $CountProcessedGPO++ } } }