0

I´m struggling with getting a list of computers from a specific OU via the Get-ADComputer cmdlet. The OU contains only computers. I specify the OU where the computers are placed and then I try to filter the objects based on hostname.

I want to list all computers whose hostname begins with "PC100". No matter what comes after the second zero.

The code:

Get-ADComputer -SearchBase "OU=PC,OU=LAB,DC=test,DC=cz" -Filter * | Select-Object name | where -Property Name -Match "PC100*"

I went through plenty of articles but haven't figured it out yet. PowerShell doesn't return any error, it simply doesn't generate any output.

1 Answer 1

1

Try this one

Get-ADComputer -SearchBase "OU=PC,OU=LAB,DC=test,DC=cz" -Filter {Name -eq "PC100"} -Properties Name | Select-Object Name

This assumes that PC organizational unit is nested under LAB, and that the name of the computer is exactly PC100. If you don't know the exact name and you know that it PC100 is part of the name, change it to -Filter {Name -like "*PC100*"}

And don't pull all properties when you don't need them, it can cause potential performance issues

Sign up to request clarification or add additional context in comments.

2 Comments

That´s exactly it. I needed to filter all the computers whose part of the name is PC100. Thank you.
No problem, glad I could help :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.