Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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 *
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading