# Get-ADUser -Filter error

**URL:** <https://forums.powershell.org/t/get-aduser-filter-error/18975>\
**Category:** PowerShell Help\
**Created:** [March 31, 2022, 9:21am UTC](https://forums.powershell.org/t/get-aduser-filter-error/18975 "2022-03-31T09:21:02Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![David\_Sylvest](https://avatars.discourse-cdn.com/v4/letter/d/ecccb3/32.png) [@David\_Sylvest](https://forums.powershell.org/u/David_Sylvest)\
**Post date:** [March 31, 2022, 9:21am UTC](https://forums.powershell.org/t/get-aduser-filter-error/18975/1 "2022-03-31T09:21:02Z")

</div>

Hi.

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…  
 ![image](https://us1.discourse-cdn.com/flex019/uploads/powershell/original/2X/0/05777f06020998370fdea645b19ef3c73812a30b.png)

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

```

---

<div class="post-metadata">

**Author:** ![Olaf](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/olaf/32/992_2.png) [@Olaf](https://forums.powershell.org/u/Olaf)\
**Post date:** [March 31, 2022, 9:27am UTC](https://forums.powershell.org/t/get-aduser-filter-error/18975/2 "2022-03-31T09:27:14Z")

</div>

If you know the sAMAccountName you can use

```auto
Get-ADUser -Identity $($user.SamAccountName)

```

---

<div class="post-metadata">

**Author:** ![David\_Sylvest](https://avatars.discourse-cdn.com/v4/letter/d/ecccb3/32.png) [@David\_Sylvest](https://forums.powershell.org/u/David_Sylvest)\
**Post date:** [March 31, 2022, 9:40am UTC](https://forums.powershell.org/t/get-aduser-filter-error/18975/3 "2022-03-31T09:40:42Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![matt-bloomfield](https://avatars.discourse-cdn.com/v4/letter/m/dec6dc/32.png) [@matt-bloomfield](https://forums.powershell.org/u/matt-bloomfield)\
**Post date:** [March 31, 2022, 9:53am UTC](https://forums.powershell.org/t/get-aduser-filter-error/18975/4 "2022-03-31T09:53:24Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Olaf](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/olaf/32/992_2.png) [@Olaf](https://forums.powershell.org/u/Olaf)\
**Post date:** [March 31, 2022, 9:55am UTC](https://forums.powershell.org/t/get-aduser-filter-error/18975/5 "2022-03-31T09:55:40Z")

</div>

Wow. Great catch. You really have an eye for details. 👍🏽 👏🏽

---

<div class="post-metadata">

**Author:** ![David\_Sylvest](https://avatars.discourse-cdn.com/v4/letter/d/ecccb3/32.png) [@David\_Sylvest](https://forums.powershell.org/u/David_Sylvest)\
**Post date:** [March 31, 2022, 10:32am UTC](https://forums.powershell.org/t/get-aduser-filter-error/18975/6 "2022-03-31T10:32:20Z")

</div>

“¤!?”%/!"¤!! 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:

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:18pm UTC](https://forums.powershell.org/t/get-aduser-filter-error/18975/7 "2024-05-16T20:18:07Z")

</div>


