I have many scripts that follow the same format to export info into a spreadsheet. I hope to get some assistance with returning lines for when an object is not found. In this particular situation - I have a script that gives information into a spreadsheet from Usernames. If the username is not found, I would like to return an error message in the line. A similar topic was found but the information I have and would like is different than the OP ( https://community.spiceworks.com/topic/2021853-foreach-on-ad-users-that-returns-missing-values). Below is my powershell code of which I like to keep it simple when possible so I can use it in other scripts. Any help is greatly appreciated!
Powershell
Import-ModuleActiveDirectory$users=ForEach($userin$(Get-ContentUsernames.txt)){Get-AdUser$user-PropertiesName,DisplayName,Department,...