Last active
October 29, 2020 18:28
-
-
Save bill-long/97af765087ada1d0d46cfa12b479328d to your computer and use it in GitHub Desktop.
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
$forest = [System.DirectoryServices.ActiveDirectory.Forest]::GetCurrentForest() | |
$gc = $forest.FindGlobalCatalog() | |
$searcher = $gc.GetDirectorySearcher() | |
$searcher.Filter = "(&(objectClass=user)(objectSID=*))" | |
# Since we're not setting a page size, this will return 1000 items and then stop | |
$objects = $searcher.FindAll() | |
$sidList = @() | |
foreach ($o in $objects) { | |
$sid = New-Object System.Security.Principal.SecurityIdentifier(($o.Properties["objectSid"][0]), 0) | |
$sidList += $sid | |
} | |
Write-Host "Found $($sidList.Count) SIDs. Starting resolve loop. Ctrl-C to stop." | |
# We have 1000 sids. Look them up in a loop, and log any errors. | |
$count = 0 | |
$errorCount = 0 | |
while ($true) { | |
foreach ($sid in $sidList) { | |
try { | |
$count += 1 | |
Write-Progress -Activity "Resolving $sid" -Status "$count total / $errorCount errors" | |
$sid.Translate("System.Security.Principal.NTAccount") | Out-Null | |
} catch { | |
$errorCount += 1 | |
Write-Error $_ | |
Write-EventLog -LogName "Application" -Source "Perflib" -EventId 12345 -EntryType Error -Message $_ | |
} | |
Start-Sleep -Milliseconds 100 | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment