Solved

Computer Names in OU

Posted on 2015-02-03
3
71 Views
Last Modified: 2015-02-03
I am trying to get a list of computer names that are in a specific OU. There has to be a way of getting that to happen in Powershell. Anyone done this before?
0
Comment
Question by:stakor
3 Comments
 
LVL 39

Accepted Solution

by:
footech earned 500 total points
ID: 40586079
You just have to use the -searchbase parameter of Get-ADComputer with the distinguishedname of the OU.
Get-ADComputer -filter * -searchbase "OU=someOU,DC=domain,DC=com" | Select name

Open in new window

If you like you can also use the -searchscope parameter (set to "OneLevel") to limit the query so that it doesn't search child OUs.
0
 
LVL 83

Expert Comment

by:oBdA
ID: 40586081
Assuming a DC running W2k8R2 or later:
 Import-Module ActiveDirectory
Get-ADComputer -Filter * -SearchBase "OU=SomeDeeperOU,OU=SomeOU,DC=some,DC=domain,DC=local"

Open in new window

0
 
LVL 12

Expert Comment

by:FarWest
ID: 40586082
check this
$ou = "OU=Workstations,OU=MyOU,DC=Fabrikam,DC=com"

$Computers = Get-ADComputer -Filter '*' -SearchBase $ou

$Computers | Foreach { $_.DNSHostName } | Out-File -Filepath "output.txt"

Open in new window


please note you have to import ActiveDirectory PowerShell Module
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
This article will help you understand what HashTables are and how to use them in PowerShell.
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

808 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question