From 4f5bf323c211b37aedb8ae8f09cff6be5d68b0d6 Mon Sep 17 00:00:00 2001 From: Matt Date: Sat, 19 Sep 2026 05:07:11 -0700 Subject: [PATCH] change to progress bar for powershell script --- files/dashboard/index.php | 2 +- files/restricted-group-check.ps1 | 36 +++++++++++++++++++++++++------- templates/app.py | 9 ++++---- 3 files changed, 34 insertions(+), 13 deletions(-) diff --git a/files/dashboard/index.php b/files/dashboard/index.php index c6e007f..ad6f56a 100644 --- a/files/dashboard/index.php +++ b/files/dashboard/index.php @@ -50,7 +50,7 @@ $index_duration = json_decode(file_get_contents('http://172.17.0.1:5000/index_du Since AD has no way to look this up, this makes it challenging to match groups to OUs.

This site has all restricted groups indexed by GPO and OU.
Search is case insensitive and supports partial match.
- The OUs liked to the GPOs will show up as a hover tooltip on the GPO name.
+ The OUs linked to the GPOs will show up as a hover tooltip on the GPO name.
Clicking on the GPO name will list all linked OUs.

diff --git a/files/restricted-group-check.ps1 b/files/restricted-group-check.ps1 index eaebede..fc1a6f0 100644 --- a/files/restricted-group-check.ps1 +++ b/files/restricted-group-check.ps1 @@ -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 "..." + diff --git a/templates/app.py b/templates/app.py index 46b3ec4..d7a4ef6 100644 --- a/templates/app.py +++ b/templates/app.py @@ -77,10 +77,11 @@ def index_duration(): try: start_timestamp = data[0]['init_timestamp'] end_timestamp = data[0]['timestamp'] - duration = (datetime.strptime(end_timestamp, fmt) - datetime.strptime(start_timestamp, fmt)).total_seconds() / 60 - return jsonify({"duration": duration, "start_timestamp": start_timestamp, "end_timestamp": end_timestamp}) + duration = int((datetime.strptime(end_timestamp, fmt) - datetime.strptime(start_timestamp, fmt)).total_seconds() / 60) + gpo_link_count = data[0]['gpo_links'] + return jsonify({"duration": duration, "start_timestamp": start_timestamp, "end_timestamp": end_timestamp, "gpo_links": gpo_link_count}) except: - return jsonify({'duration': "whoops"}) + return jsonify({'duration': "whoops", 'error': 'yes, figure it out brah'}) @app.route("/linked_ous", methods=["GET"]) def linked_ous(): @@ -139,4 +140,4 @@ def test(): return jsonify({"result": "test", "OU_Root": root_ou}) if __name__ == '__main__': - app.run(debug=True, host='{{ api_service_bind_ip }}', port={{ api_service_port }}) \ No newline at end of file + app.run(debug=False, host='{{ api_service_bind_ip }}', port={{ api_service_port }}) \ No newline at end of file