# Trouble with Get-Aduser from CSV

**URL:** <https://forums.powershell.org/t/trouble-with-get-aduser-from-csv/4790>\
**Category:** PowerShell Help\
**Created:** [September 1, 2015, 1:32am UTC](https://forums.powershell.org/t/trouble-with-get-aduser-from-csv/4790 "2015-09-01T01:32:45Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![hcsmarnold](https://avatars.discourse-cdn.com/v4/letter/h/838e76/32.png) [@hcsmarnold](https://forums.powershell.org/u/hcsmarnold)\
**Post date:** [September 1, 2015, 1:32am UTC](https://forums.powershell.org/t/trouble-with-get-aduser-from-csv/4790/1 "2015-09-01T01:32:45Z")

</div>

Trying to Get-Aduser based on description. I have a csv with a list of serial numbers. These are added to the description field of Ad users. When I run my code nothing returns.  
CSV:  
Description  
5CD50801ZC  
98VGJ42  
J8TFJ42  
6NVFJ42  
7PQFJ42  
1GTFJ42

```
Code:
`
$csv = Import-Csv C:\scripting\chromebook1.csv 

foreach ($line in $csv)
{get-aduser -Filter {description -like $line} -SearchBase 'OU=LEADERSHIP,DC=DS,DC=NET'}
`
```

---

<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:** [September 1, 2015, 1:42am UTC](https://forums.powershell.org/t/trouble-with-get-aduser-from-csv/4790/2 "2015-09-01T01:42:31Z")

</div>

Two things here: One, the -Like operator requires some wildcards, if you’re planning to look for a string that contains something else. Also, you need to be looking at $line.Description, rather than just $line. Try this:

```
$csv = Import-Csv C:\scripting\chromebook1.csv 

foreach ($line in $csv)
{
    get-aduser -Filter "description -like '*$($line.Description)*'" -SearchBase 'OU=LEADERSHIP,DC=DS,DC=NET'
}
```

I’ve changed your -Filter argument from a script block literal to a double-quoted string, based on past experience with the AD cmdlets where sometimes the script block syntax doesn’t work the way you expect it to.

---

<div class="post-metadata">

**Author:** ![hcsmarnold](https://avatars.discourse-cdn.com/v4/letter/h/838e76/32.png) [@hcsmarnold](https://forums.powershell.org/u/hcsmarnold)\
**Post date:** [September 1, 2015, 1:48am UTC](https://forums.powershell.org/t/trouble-with-get-aduser-from-csv/4790/3 "2015-09-01T01:48:32Z")

</div>

That work, thanks!

Question, why is the “$” required outside of the ($line.description)?

---

<div class="post-metadata">

**Author:** ![hcsmarnold](https://avatars.discourse-cdn.com/v4/letter/h/838e76/32.png) [@hcsmarnold](https://forums.powershell.org/u/hcsmarnold)\
**Post date:** [September 1, 2015, 1:49am UTC](https://forums.powershell.org/t/trouble-with-get-aduser-from-csv/4790/4 "2015-09-01T01:49:36Z")

</div>

.

---

<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:** [September 1, 2015, 1:51am UTC](https://forums.powershell.org/t/trouble-with-get-aduser-from-csv/4790/5 "2015-09-01T01:51:12Z")

</div>

That’s a sub-expression operator, and is what you use in strings when you want to expand something more complex than just a simple variable name. Otherwise, $line would get expanded, and the text “.Description” would become a literal part of the string, which is not what we want.

---

<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:44pm UTC](https://forums.powershell.org/t/trouble-with-get-aduser-from-csv/4790/6 "2024-05-16T20:44:51Z")

</div>


