# Pulling ADUser Info

**URL:** <https://forums.powershell.org/t/pulling-aduser-info/2364>\
**Category:** PowerShell Help\
**Created:** [March 21, 2014, 2:33am UTC](https://forums.powershell.org/t/pulling-aduser-info/2364 "2014-03-21T02:33:34Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![eric-salamone](https://avatars.discourse-cdn.com/v4/letter/e/f0a364/32.png) [@eric-salamone](https://forums.powershell.org/u/eric-salamone)\
**Post date:** [March 21, 2014, 2:33am UTC](https://forums.powershell.org/t/pulling-aduser-info/2364/1 "2014-03-21T02:33:34Z")

</div>

I am little confused about why my little script I wrote is not having an output. In the beginning I have a read-host and unless I’m not understanding at all, I was under the impression that the $user variable will be filtered through until it matches a property. This seems to be a simple script yet I’m lost on why it is not working. Any help would be greatly appreciated.

Get-ADUser -filter {(Name -like “$user”) -or (SAMAccountName -like “$user”) -or (SN -like “$user”)} `  
-Properties \* | select Name, EmailAddress, SAMAccountName, SN | fl

---

<div class="post-metadata">

**Author:** ![donj](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/donj/32/137_2.png) [@donj](https://forums.powershell.org/u/donj)\
**Post date:** [March 21, 2014, 2:36am UTC](https://forums.powershell.org/t/pulling-aduser-info/2364/2 "2014-03-21T02:36:56Z")

</div>

You probably don’t need all of that. You can probably do:

Get-ADUser $user

It automatically runs that against the -Identity parameter instead, and tries to match against name, CN, and samAccountName. I don’t think it matches against surname, though.

Ultimately, what’s probably happening is “$user” is being sent as a literal string to the domain controller, and since you don’t have a user named “$user” it isn’t working. It’s because the script block {} prevents the variable from being evaluated before the filter is shipped off to the DC. People run into the same problem trying to use $null, for example.

As a test, try putting a legit username in place of $user - make sure it works with a hardcoded value, in other words. If it does, then your problem is that it isn’t evaluating $user as a variable but is instead sending it as a literal.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex019/uploads/powershell/original/1X/385e4f9fe133561ad30a814262fe0e0ae6bc3ef0.png) [@system](https://forums.powershell.org/u/system)\
**Post date:** [March 21, 2014, 2:37am UTC](https://forums.powershell.org/t/pulling-aduser-info/2364/3 "2014-03-21T02:37:52Z")

</div>

Just for giggles, try it like this. The -Filter parameters to the AD cmdlets actually accept strings, not ScriptBlocks (though all the examples show the wrong syntax, which can be confusing.) Sometimes they don’t work the way you’d expect when you pass in a ScriptBlock and allow it to be converted automatically to a string.

```
Get-ADUser -Properties * -Filter "Name -eq '$user' -or SamAccountName -eq '$user' -or SN -eq '$user'" |
Select-Object Name, EmailAddress, SAMAccountName, SN |
Format-List
```

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex019/uploads/powershell/original/1X/385e4f9fe133561ad30a814262fe0e0ae6bc3ef0.png) [@system](https://forums.powershell.org/u/system)\
**Post date:** [March 21, 2014, 2:55am UTC](https://forums.powershell.org/t/pulling-aduser-info/2364/4 "2014-03-21T02:55:57Z")

</div>

Just had another thought on this: Does your $user variable’s value contain wildcards? If so, you’d need to change those -eq operators back to -like in my example (and that might also explain why it’s not working the way you expected with the original ScriptBlock syntax.)

---

<div class="post-metadata">

**Author:** ![eric-salamone](https://avatars.discourse-cdn.com/v4/letter/e/f0a364/32.png) [@eric-salamone](https://forums.powershell.org/u/eric-salamone)\
**Post date:** [March 21, 2014, 3:30am UTC](https://forums.powershell.org/t/pulling-aduser-info/2364/5 "2014-03-21T03:30:58Z")

</div>

Mr. Jones and Mr. Wyatt,

Thank you for the quick reply and correction. The problem was the script blocks. I was using SAMAccount and SN as tests, because my small vm test network doesn’t have exchange to test for mail or a edipi that I will be using to search for users at work.

---

<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:52pm UTC](https://forums.powershell.org/t/pulling-aduser-info/2364/6 "2024-05-16T20:52:18Z")

</div>

Closed on May 16, 2024, 8:52pm UTC


