Jose Colmenares
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
and to consult for name I used that
How can I join both commands to query on a particular OU machines starting with the specific name?
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"
and to consult for name I used that
Get-ADComputer -Filter "Name -like 'Win81*'"
How can I join both commands to query on a particular OU machines starting with the specific name?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
$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
ASKER
VERY NICEEEEEEEEEEE, thank you very much.
Glad to help! :)
ASKER
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"
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.
To just choose the DnsHostName property, yes you would need to pipe to the Select-Object command as you have shown.
ASKER
if only I want the DNSHostName in the list? how can i put the parameter?