add gpo counter variable to powershell script for visbility
This commit is contained in:
@@ -18,6 +18,8 @@ if (Test-Path $OutputFile) {
|
||||
Write-Output "Enumerating OUs under '$TargetOU' ..."
|
||||
Add-Content -Path $OutputFile -Value "---"
|
||||
Add-Content -Path $OutputFile -Value "- root_ou: $TargetOU"
|
||||
$Start_Date = (Get-Date).ToString('MM/dd/yyyy hh:mm:ss tt')
|
||||
Add-Content -Path $OutputFile -Value " init_timestamp: $Start_Date"
|
||||
$ouObjects = Get-ADObject `
|
||||
-Filter 'ObjectClass -eq "organizationalUnit"' `
|
||||
-SearchBase $TargetOU `
|
||||
@@ -69,7 +71,10 @@ Add-Content -Path $OutputFile -Value " gpo_links: $($gpoLinks.Count)"
|
||||
|
||||
|
||||
Add-Content -Path $OutputFile -Value " configured_gpos:"
|
||||
$ou_counter = 0
|
||||
foreach ($gpoGuid in $gpoLinks.Keys) {
|
||||
$ou_counter++
|
||||
|
||||
try {
|
||||
$gpo = Get-GPO -Guid $gpoGuid -ErrorAction Stop
|
||||
}
|
||||
@@ -77,18 +82,19 @@ foreach ($gpoGuid in $gpoLinks.Keys) {
|
||||
Write-Warning "Unable to retrieve GPO $gpoGuid – skipping."
|
||||
continue
|
||||
}
|
||||
Write-Host "GPO: $($gpo.DisplayName)"
|
||||
Write-Host "GPO $ou_counter of $($gpoLinks.Count): $($gpo.DisplayName)"
|
||||
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]
|
||||
Write-Host "Linked OUs:"
|
||||
Add-Content -Path $OutputFile -Value " Linked_OUs:"
|
||||
$linkedOUs = $gpoLinks[$gpoGuid] # <-- the list we built earlier
|
||||
Add-Content -Path $OutputFile -Value " - Linked_OUs:"
|
||||
foreach ($ouDn in $linkedOUs) {
|
||||
Write-Host "$ouDn"
|
||||
Add-Content -Path $OutputFile -Value " - $ouDn"
|
||||
}
|
||||
|
||||
|
||||
# Pull the XML report
|
||||
try {
|
||||
$xmlString = Get-GPOReport -Guid $gpoGuid -ReportType Xml -ErrorAction Stop
|
||||
@@ -97,8 +103,9 @@ foreach ($gpoGuid in $gpoLinks.Keys) {
|
||||
Write-Warning "Unable to generate XML report for $($gpo.DisplayName)."
|
||||
continue
|
||||
}
|
||||
|
||||
$xml = [xml]$xmlString
|
||||
# process the XML data
|
||||
|
||||
$ns = New-Object System.Xml.XmlNamespaceManager ($xml.NameTable)
|
||||
$ns.AddNamespace('m', 'http://www.microsoft.com/GroupPolicy/Settings') # default namespace
|
||||
$ns.AddNamespace('q1', 'http://www.microsoft.com/GroupPolicy/Settings/Security')
|
||||
@@ -113,10 +120,12 @@ foreach ($gpoGuid in $gpoLinks.Keys) {
|
||||
$adGroupName = ($rg.SelectSingleNode('q1:GroupName/t:Name', $ns)).InnerText
|
||||
$localGroupName = ($rg.SelectSingleNode('q1:Memberof/t:Name', $ns)).InnerText
|
||||
$plainAD_Groupname = ($adGroupName -split '\\')[-1]
|
||||
Write-Output "AD Group: $adGroupName - Local Group: $localGroupName"
|
||||
#Write-Output "AD Group: $adGroupName - Local Group: $localGroupName"
|
||||
Add-Content -Path $OutputFile -Value " - ad_group: $plainAD_Groupname"
|
||||
Add-Content -Path $OutputFile -Value " local_group: $localGroupName"
|
||||
}
|
||||
Add-Content -Path $OutputFile -Value ""
|
||||
}
|
||||
$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 "..."
|
||||
|
||||
Reference in New Issue
Block a user