Get-ADUser -Filter error


So i am working on a script, and i’m trying to boil things down to minimize errors. So this is my minimal version. i get an error “Get-ADUser : The search filter cannot be recognized”. I’ve tried multiple things but at this point i am baging my head against a wall.

My csv is this…

$list = Import-CSV -Delimiter ";" -Path c:\pathtocsv.csv
ForEach($user in $list){
$ADUser = Get-ADUser -Filter "SamAccountName -eq '$($user.SamAccountName)'"
write-host $ADUser}

If you know the sAMAccountName you can use

Get-ADUser -Identity $($user.SamAccountName)
1 Like

Hi Olaf.

Thanks for your reply. I get the following error:
“Get-ADUser : Cannot validate argument on parameter ‘Identity’. The argument is null. Provide a valid value for the argument, and then try running the command”

So seems like for whatever reason i don’t get the value out for each user, however i get an error for each line in the CSV file.

The dashes under the SamAccountName column in your picture would suggest you have a space after SamAccountName in your column header.


Wow. Great catch. You really have an eye for details. :+1:t4: :clap:t4:

1 Like

“¤!?”%/!"¤!! god dammit! the ammount of time i’ve spend on that darn space!

And thank you so much for seeing that mistake, thats impressive:slight_smile: