powershellactive-directoryget-aduser

Powershell - I try to list computers that have a specific string in their description, but I'm unable to create a proper command


In my understanding I made a code that first lists computers with all their properties, then selects only the description property and after that it filters the computers whether they contain the specified string.

Get-ADComputer -Properties * | Select-Object Description | Where $_.Description -Contains "Name"

I received this error: Where-Object : Cannot validate argument on parameter 'Property'. The argument is null or empty. Provide an argument that is not null or empty, and then try the command again.

I tried multiple versions of this code on par of my skill for now, such as: Get-ADComputer -Properties * | Where $_.Description -Contains "Name" (Select-Object Description)

Or I completely omitted the Select part. Get-ADComputer -Properties * | Where $_.Description -Contains "Name"

I'm only starting to get to know Powershell and to be completely honest I'm stuck. I would like to ask you to inspect my code and tell me what is wrong or should be changed. Preferably a simple solution, as in "one liner" like my code above.

Thanks in advance!


Solution

  • This should do it by filtering upfront

    Get-ADComputer -Filter 'Description -like "*Name*"' -Properties *