# Get Computer Name by Description

**URL:** <https://forums.powershell.org/t/get-computer-name-by-description/6445>\
**Category:** PowerShell Help\
**Created:** [May 13, 2016, 12:30am UTC](https://forums.powershell.org/t/get-computer-name-by-description/6445 "2016-05-13T00:30:58Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![brad-sam](https://avatars.discourse-cdn.com/v4/letter/b/258eb7/32.png) [@brad-sam](https://forums.powershell.org/u/brad-sam)\
**Post date:** [May 13, 2016, 12:30am UTC](https://forums.powershell.org/t/get-computer-name-by-description/6445/1 "2016-05-13T00:30:58Z")

</div>

Hi,  
I try get computer name by description  
but it not working correct  
it get just last name from my list  
This my code:  
`
$username = Get-Content “C:\Users.txt”`

`
`

`foreach ($entry in $username)
{
Get-ADComputer -Filter (“Description -Like ‘$entry’”) -Property Name,Description |
Select Name,Description |
Export-Csv “C:\CompName.csv” -NoTypeInformation
}`

---

<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:** [May 13, 2016, 12:47am UTC](https://forums.powershell.org/t/get-computer-name-by-description/6445/2 "2016-05-13T00:47:16Z")

</div>

You’re calling Export-Csv inside a loop without the -Append switch, which will just keep overwriting the file. One alternative is to turn this into a single pipeline with Export-Csv at the end (so it’s only called once, but receives multiple input objects):

```
Get-Content "C:\Users.txt" |
Get-ADComputer -Filter ("Description -Like '$_'") -Property Name,Description |
Select Name,Description |
Export-Csv "C:\CompName.csv" -NoTypeInformation
```

---

<div class="post-metadata">

**Author:** ![brad-sam](https://avatars.discourse-cdn.com/v4/letter/b/258eb7/32.png) [@brad-sam](https://forums.powershell.org/u/brad-sam)\
**Post date:** [May 13, 2016, 1:14am UTC](https://forums.powershell.org/t/get-computer-name-by-description/6445/3 "2016-05-13T01:14:06Z")

</div>

Hi Dave,

Thank you for replay, the -Append work

Thanks.

---

<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:41pm UTC](https://forums.powershell.org/t/get-computer-name-by-description/6445/4 "2024-05-16T20:41:23Z")

</div>


