Parse Read Data To ADUser

tags: convert, parse, match, aduser

Related articles


github link placeholder


Every so often we receive a request to perform some actions on a batch of users. Usually these requests don’t quite come in a desirable format, they won’t include samAccountNames, userPrincipalNames or DistinguishedNames and ultimately these are the values we need to work with to perform actions on user accounts.

Users will submit a request based on a copy of unformatted names, email addresses. Anything they can conveniantly grab. I’ve received requests that are straight copy pastas from cc’d fields or some odd excel columns that are upside down such as just a column that contains Last Name First Name , so reverse. Intead of googling Excel formuals for the nth time I found it more conveniant to write scripts around these instances.


parameter name description
-Email (mandatory set)[switch] perform ADUser match based on Email Address
-DisplayName (mandatory set)[switch] perform ADUser match based on DisplayName value
-Recoursive (switch) if main switch filter doesn't return any results, script will attempt to use the other filter to try and match
variable name description
$userList provide a CSV file that contains either Email or DisplayName or FirstName or both if using the -Recoursive switch
$exportPath predefined location and filename for output csv file containing results

The Mandatory set means that either of the two switches are required in order for the script to run, but the two of them at the same time won’t function. In the case where both switches need to be combined the -Recoursive switch comes into play. This is a fallback solution in case the selected switch fails to match or doesn’t even exist.


At runtime the script will perform the following checks and stop in case any of them fail and provide console information:


This is a sample of the CSV exported (....csv)

The console output looks like this:

PS > .\ConvertEmailToUPN.ps1 -Email -Recoursive
[ adeyoung@orbi.com ] exists in domain: True
[ Something Here ] exists in domain: False
[ Something Blank ] exists in domain: False
[ blank@display.name ] exists in domain: False
[ Isaiah Langer ] exists in domain: True
[ mgraham@orbi.com ] exists in domain: True
[ Something Wrong ] exists in domain: False
Information exported to file: .\4.10.2021_parseUserExport.csv