Quantcast
Channel: The Official Scripting Guys Forum! forum
Viewing all articles
Browse latest Browse all 15028

Get-AdUser error checking

$
0
0

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!


Viewing all articles
Browse latest Browse all 15028

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>