Link to home
Start Free TrialLog in
Avatar of Jose Colmenares
Jose ColmenaresFlag for Chile

asked on

Consult machines in a specific OU with a specific name of machines

Hello all,

I need to know the machines in a specific OU of my AD, but additional I need filter for name, only need the machines that the name start with W81.

To limit the query to a particular OU I used this command
Get-ADComputer -Filter * -SearchBase "OU=IT, DC=contoso, DC=com"

Open in new window


and to consult for name I used that
Get-ADComputer -Filter "Name -like 'Win81*'"

Open in new window



How can I join both commands to query on a particular OU machines starting with the specific name?
ASKER CERTIFIED SOLUTION
Avatar of Ben Personick (Previously QCubed)
Ben Personick (Previously QCubed)
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Jose Colmenares

ASKER

Excellent

if only I want the DNSHostName in the list? how can i put the parameter?
$Results = Get-ADComputer -Filter * -SearchBase "OU=IT, DC=contoso, DC=com"  | Select-object -property * #Selects ALL properties of the computers just in case DNSHostName isn;t a 'standard' property
$Results | where-object {$_.name -like "Win81*" } | Select-object -property DNSHostName 

Open in new window

VERY NICEEEEEEEEEEE, thank you very much.
Excelent
Question's already closed, by why would you not do everything with the Get-ADComputer cmdlet?  You already got the parameters, just combine them.
Get-ADComputer -Filter "Name -like 'Win81*'" -SearchBase "OU=IT,DC=contoso,DC=com"

Open in new window

How would you return only the DNSHostName without using an additional command to select only that property?
I was just referring to returning the desired computer objects.  It's always best practice to filter as early as possible (though for small sets you're not likely to observe the difference).

To just choose the DnsHostName property, yes you would need to pipe to the Select-Object command as you have shown.