Author Posts

May 13, 2016 at 6:00 am

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
}

May 13, 2016 at 6:17 am

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

May 13, 2016 at 6:44 am

Hi Dave,

Thank you for replay, the -Append work

Thanks.