change to progress bar for powershell script
This commit is contained in:
@@ -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.<p>
|
Since AD has no way to look this up, this makes it challenging to match groups to OUs.<p>
|
||||||
This site has all restricted groups indexed by GPO and OU.<br>
|
This site has all restricted groups indexed by GPO and OU.<br>
|
||||||
Search is case insensitive and supports partial match. <br>
|
Search is case insensitive and supports partial match. <br>
|
||||||
The OUs liked to the GPOs will show up as a hover tooltip on the GPO name.<br>
|
The OUs linked to the GPOs will show up as a hover tooltip on the GPO name.<br>
|
||||||
Clicking on the GPO name will list all linked OUs.<br><p>
|
Clicking on the GPO name will list all linked OUs.<br><p>
|
||||||
</div>
|
</div>
|
||||||
<div class="container">
|
<div class="container">
|
||||||
|
|||||||
@@ -60,8 +60,6 @@ if (-not $gpoLinks.Count) {
|
|||||||
exit
|
exit
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Write-Host "Found $($gpoLinks.Count) distinct GPO(s) linked in the OU tree."
|
Write-Host "Found $($gpoLinks.Count) distinct GPO(s) linked in the OU tree."
|
||||||
Add-Content -Path $OutputFile -Value " gpo_links: $($gpoLinks.Count)"
|
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
|
# 3. For each GPO, get an XML report and pull RestrictedGroup nodes
|
||||||
# ----------------------------------------------------
|
# ----------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
Add-Content -Path $OutputFile -Value " configured_gpos:"
|
Add-Content -Path $OutputFile -Value " configured_gpos:"
|
||||||
$ou_counter = 0
|
$ou_counter = 0
|
||||||
|
$startTime = Get-Date
|
||||||
|
$totalItems = $gpoLinks.Count
|
||||||
|
|
||||||
foreach ($gpoGuid in $gpoLinks.Keys) {
|
foreach ($gpoGuid in $gpoLinks.Keys) {
|
||||||
$ou_counter++
|
$ou_counter++
|
||||||
|
|
||||||
@@ -82,11 +82,31 @@ foreach ($gpoGuid in $gpoLinks.Keys) {
|
|||||||
Write-Warning "Unable to retrieve GPO $gpoGuid – skipping."
|
Write-Warning "Unable to retrieve GPO $gpoGuid – skipping."
|
||||||
continue
|
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):"
|
Add-Content -Path $OutputFile -Value " $($gpo.DisplayName):"
|
||||||
|
|
||||||
# ok, i need to start generating a variable with all links in it
|
# ok, i need to start generating a variable with all links in it
|
||||||
|
|
||||||
|
|
||||||
# -------- Linked OUs ----------
|
# -------- Linked OUs ----------
|
||||||
$linkedOUs = $gpoLinks[$gpoGuid] # <-- the list we built earlier
|
$linkedOUs = $gpoLinks[$gpoGuid] # <-- the list we built earlier
|
||||||
Add-Content -Path $OutputFile -Value " - Linked_OUs:"
|
Add-Content -Path $OutputFile -Value " - Linked_OUs:"
|
||||||
@@ -94,7 +114,6 @@ foreach ($gpoGuid in $gpoLinks.Keys) {
|
|||||||
Add-Content -Path $OutputFile -Value " - $ouDn"
|
Add-Content -Path $OutputFile -Value " - $ouDn"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
# Pull the XML report
|
# Pull the XML report
|
||||||
try {
|
try {
|
||||||
$xmlString = Get-GPOReport -Guid $gpoGuid -ReportType Xml -ErrorAction Stop
|
$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')
|
$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 " timestamp: $Current_Date"
|
||||||
Add-Content -Path $OutputFile -Value "..."
|
Add-Content -Path $OutputFile -Value "..."
|
||||||
|
|
||||||
|
|||||||
+5
-4
@@ -77,10 +77,11 @@ def index_duration():
|
|||||||
try:
|
try:
|
||||||
start_timestamp = data[0]['init_timestamp']
|
start_timestamp = data[0]['init_timestamp']
|
||||||
end_timestamp = data[0]['timestamp']
|
end_timestamp = data[0]['timestamp']
|
||||||
duration = (datetime.strptime(end_timestamp, fmt) - datetime.strptime(start_timestamp, fmt)).total_seconds() / 60
|
duration = int((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})
|
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:
|
except:
|
||||||
return jsonify({'duration': "whoops"})
|
return jsonify({'duration': "whoops", 'error': 'yes, figure it out brah'})
|
||||||
|
|
||||||
@app.route("/linked_ous", methods=["GET"])
|
@app.route("/linked_ous", methods=["GET"])
|
||||||
def linked_ous():
|
def linked_ous():
|
||||||
@@ -139,4 +140,4 @@ def test():
|
|||||||
return jsonify({"result": "test", "OU_Root": root_ou})
|
return jsonify({"result": "test", "OU_Root": root_ou})
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
app.run(debug=True, host='{{ api_service_bind_ip }}', port={{ api_service_port }})
|
app.run(debug=False, host='{{ api_service_bind_ip }}', port={{ api_service_port }})
|
||||||
Reference in New Issue
Block a user