Last active
July 15, 2023 14:42
-
-
Save laymanstake/ef7331093fe2080a51a493cd5714e1d7 to your computer and use it in GitHub Desktop.
Required was to find out all the queries for mapped drive in GPO preference. Not a general purpose script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<# | |
.SYNOPSIS | |
MapDriveQueries.ps1 - Perform Active Directory assessment and generate a report. | |
.DESCRIPTION | |
This script find group policy preference queries for mapped drive | |
.NOTES | |
Not a general purpose script but was made for specific purpose, but in case more settings need to be picked from GPO preference then can be used as template | |
.EXAMPLE | |
MapDriveQueries.ps1 | |
#> | |
$GPOName = (Get-GPO -All).Displayname | |
$GPOReport1 = @() | |
$i = 0 | |
$maxParallelJobs = 50 | |
$jobs = @() | |
foreach ($thisGPO in $GPOName) { | |
$i++ | |
while ((Get-Job -State Running).Count -ge $maxParallelJobs) { | |
Start-Sleep -Milliseconds 50 | |
} | |
Write-Progress -Activity "Working on $($i)/$($GPOName.count) GPO ..." -Status "Querying $thisGPO" | |
$Scriptblock = { | |
param($thisGPO) | |
$outreport = @() | |
[XML]$GPO = Get-GPOReport -Name $thisGPO -ReportType xml | |
$driveMap = $GPO.GPO.User.ExtensionData.Extension.DriveMapSettings.Drive | |
if ($driveMap.Filters) { | |
if ($driveMap.Filters.FilterLdap) { | |
foreach ($filter in $driveMap.Filters.FilterLdap.searchFilter) { | |
$outreport += [pscustomobject] @{ | |
GPOName = $thisGPO | |
Drive = ($driveMap | Where-Object { $_.OuterXml -like "*FilterLdap*" }).Name | |
UNC = ($driveMap | Where-Object { $_.OuterXml -like "*FilterLdap*" }).properties.path | |
Filter = $filter | |
FilterType = "LDAP" | |
} | |
} | |
} | |
if ($driveMap.Filters.FilterUser) { | |
foreach ($filter in $driveMap.Filters.FilterUser.Name) { | |
$outreport += [pscustomobject] @{ | |
GPOName = $thisGPO | |
Drive = ($driveMap | Where-Object { $_.innerxml -like "*Filteruser*" }).Name | |
UNC = ($driveMap | Where-Object { $_.innerxml -like "*Filteruser*" }).Properties.path | |
Filter = $filter | |
FilterType = "User" | |
} | |
} | |
} | |
if ($driveMap.Filters.FilterGroup) { | |
foreach ($filter in $driveMap.Filters.FilterGroup.Name) { | |
$outreport += [pscustomobject] @{ | |
GPOName = $thisGPO | |
Drive = ($driveMap | Where-Object { $_.innerxml -like "*FilterGroup*" }).Name | |
UNC = ($driveMap | Where-Object { $_.innerxml -like "*FilterGroup*" }).Properties.path | |
Filter = $filter | |
FilterType = "Group" | |
} | |
} | |
} | |
} | |
return $outreport | |
} | |
$jobs += Start-Job -ScriptBlock $scriptBlock -ArgumentList $thisGPO | |
Write-Output "$($i)/$($GPOName.count) Powershell jobs submitted." | |
} | |
$null = $jobs | Wait-Job | |
foreach ($job in $jobs) { | |
$GPOReport1 += Receive-Job -Job $job | |
} | |
$null = Get-Job | remove-Job | |
$GPOReport1 | Select-Object GPOName, Drive, UNC, Filter, FilterType | Format-Table |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment