Greetings all,
Scenario: I've been given a list of users who are (apparently) in Active Directory. I've been asked to get their username and e-mail address from AD. The code used is as follows:
$users = Get-Content C:\Path\to\users.txt
**Content of users.txt is:
**blogs, joe
**smith, generic
**user, not exist
**davies, generic
foreach ($user in $users) { Get-ADUser -ldapfilter "(displayname=$user)" -Property * |
Select-Object -Property displayname,samaccountname,mail }
The above works great and outputs the following:
displayname samaccountname mail
-------------- ------------------- -----
blogs, joe blogsj joe.blogs@domain.com
smith, generic smithg generic.smith@domain.com
davies, generic daviesg generic.davies@domain.com
Fine and dandy but is it at all possible to display users who cannot be found so the output can be (or similar to) the below:
nameinfile displayname samaccountname mail
----------- -------------- ------------------- -----
blogs, joe blogs, joe blogsj joe.blogs@domain.com
smith, generic smith, generic smithg generic.smith@domain.com
user, not exist <> <> <>
davies, generic davies, generic daviesg generic.davies@domain.com
(Granted I probably don't need 'displayname' here).
Many thanks in advance.
~IceWolf762