Powershell Dynamic Menu from Object Array

Posted on Posted in Active Directory, Powershell

Ya know what grinds my gears?  Getting a CSV of employees without a unique key column – no samaccountname, UPN, email, DistinguishedName, SID – nothing.  Sometimes you’ll even get supplied with a column of <firstname><space><lastname> using 3rd party information that doesn’t mesh with AD info either.  Nice.

The function below can be used with an interactive script so you can select the proper object to report on/target/add to another array.  Without any editing the AD objects will display their DN when enumerated from the hash.  Input validation is also present and will only accept the range of numbers determined within the function or cancel and return null.