change to progress bar for powershell script

This commit is contained in:
2026-09-19 05:07:11 -07:00
parent 364da0159b
commit 4f5bf323c2
3 changed files with 34 additions and 13 deletions
+28 -8
View File
@@ -1,4 +1,4 @@
# ------------------------------------------------------------------
# ------------------------------------------------------------------
# 0. Load modules (they are usually loaded by default, but be safe)
# ------------------------------------------------------------------
@@ -60,8 +60,6 @@ if (-not $gpoLinks.Count) {
exit
}
Write-Host "Found $($gpoLinks.Count) distinct GPO(s) linked in the OU tree."
Add-Content -Path $OutputFile -Value " gpo_links: $($gpoLinks.Count)"
@@ -69,9 +67,11 @@ Add-Content -Path $OutputFile -Value " gpo_links: $($gpoLinks.Count)"
# 3. For each GPO, get an XML report and pull RestrictedGroup nodes
# ----------------------------------------------------
Add-Content -Path $OutputFile -Value " configured_gpos:"
$ou_counter = 0
$startTime = Get-Date
$totalItems = $gpoLinks.Count
foreach ($gpoGuid in $gpoLinks.Keys) {
$ou_counter++
@@ -82,11 +82,31 @@ foreach ($gpoGuid in $gpoLinks.Keys) {
Write-Warning "Unable to retrieve GPO $gpoGuid skipping."
continue
}
Write-Host "GPO $ou_counter of $($gpoLinks.Count): $($gpo.DisplayName)"
# Status Display
$percentComplete = [int]( ($ou_counter / $gpoLinks.Count) * 100 )
if ($ou_counter -gt 0) {
$elapsed = (Get-Date) - $startTime # Timespan
$averagePerItem = $elapsed.TotalSeconds / $ou_counter
$remainingItems = $totalItems - $ou_counter
$secondsRemaining = [int]($averagePerItem * $remainingItems)
} else {
$secondsRemaining = -1 # Unknown PowerShell will not display it
}
Write-Progress `
-Activity "Processing GPOs" `
-Status $gpo.DisplayName `
-PercentComplete $percentComplete `
-SecondsRemaining $secondsRemaining `
-CurrentOperation "GPO $ou_counter of $totalItems"
# Update YAML
Add-Content -Path $OutputFile -Value " $($gpo.DisplayName):"
# ok, i need to start generating a variable with all links in it
# -------- Linked OUs ----------
$linkedOUs = $gpoLinks[$gpoGuid] # <-- the list we built earlier
Add-Content -Path $OutputFile -Value " - Linked_OUs:"
@@ -94,7 +114,6 @@ foreach ($gpoGuid in $gpoLinks.Keys) {
Add-Content -Path $OutputFile -Value " - $ouDn"
}
# Pull the XML report
try {
$xmlString = Get-GPOReport -Guid $gpoGuid -ReportType Xml -ErrorAction Stop
@@ -129,3 +148,4 @@ foreach ($gpoGuid in $gpoLinks.Keys) {
$Current_Date = (Get-Date).ToString('MM/dd/yyyy hh:mm:ss tt')
Add-Content -Path $OutputFile -Value " timestamp: $Current_Date"
Add-Content -Path $OutputFile -Value "..."