So, Recently my team and I are working on Integrating AD into another application in our environment. I, however, had to supply a list of GUID’s from Active Directory and return them to the end user to review. Apparently, they bind the existing user’s via GUID to prevent any mix-up and could only supply me their Given and Surname. I threw them in a CSV and used the following Powershell code below to generate the list they wanted.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
Remove-Variable * -ErrorAction SilentlyContinue; Remove-Module *; $error.Clear(); Clear-Host $mytable = Import-Csv -Path "C:\Feed.csv" -Header ID,Data $HashTable=@{} foreach($r in $mytable) { if ($r.ID -notlike '#*') {$HashTable[$r.ID]=$r.Data} $Name = $r.Data + ", " + $r.ID.Substring(0,3) + "*" #Write-Host $Name $User = Get-ADUser -Filter 'Name -like $Name' -Properties Name, objectGUID Write-Host $User.Name $User.ObjectGUID #Get-ADUser -Filter 'GivenName -like $r.ID' #Get-ADUser -Filter * } |