Hi all,
I have a script that reads from a CSV and then uses one of the fields to match the username in AD (SamAccountName property). I need to do some error checking though to stop the script if the user doesn't exist.
I came up with the following but of course the error fails on the first command.
$UserProperties = Get-ADUser $_.Username -Properties * If (!($UserProperties.SamAccountName -eq $Null)) { Do Stuff }
Can anyone suggest the best way to go about checking the username in the CSV is a valid username?
Many thanks!