Solved

Computer Names in OU

Posted on 2015-02-03
3
70 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

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

I thought I'd write this up for anyone who has a request to create an anonymous whistle-blower-type submission form created using SharePoint 2010 (this would probably work the same for 2013). It's not 100% fool-proof but it's as close as you can get…
A procedure for exporting installed hotfix details of remote computers using powershell
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

863 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now