Hello,
I currently have a PS script that shows Disabled and Enabled users within Active Directory. Everything works fine; except for the fact if the user does not exist, it will display the following error within the console:
Get-ADUser : Cannot find an object with identity: 'test1'
I am green with PS and I need help adding an else if statement. If the user is not found, I want it to show "User not found". My results are exported to a csv file.
Here is my code:
$userlist = Import-Csv "C:\Scripts\AD User Status\users1.csv" foreach($user in $userlist){ Get-ADUser -Server "My Domain" -Identity $user.username -Properties * | Select DisplayName, SAMAccountName, Enabled | Export-Csv "C:\Scripts\AD User Status\UserStatus.csv" -NoTypeInformation -Append }
I appreciate your help!
:)