I have a list of DisplayNames and I wan't to look up each of the SamAccountNames, but when I do I want to keep a blank line when there is no SamAccountName is found. Right now when I run it against my list of 400 DisplayNames the output is only 350, but I don't know where those 50 in my list that are missing. What I have right now is:
Get-Content C:\list.txt | ForEach-Object {(Get-ADUser -Filter {DisplayName -eq $_}).SamAccountName}
I've used a similar syntax with other commands that do produce blank lines, but as far as I can tell using -Filter seems to change it some how that causes the blank lines to no longer be present.
So, instead of something like this:
jonesb
williamsj
bakere
I get:
jonesb
williamsj
bakere