List all servers in Active Directory

Need a script to list all servers in Active Directory.  From Windows 2000 Server all the way up to and including Windows Server 2008 R2.  Need to make sure all Editions are included.  e.g. Advanced, Standard, Enterprise, Datacenter and 32-bit and 64-bit versions.

LVL 37
Carl WebsterAsked:
Who is Participating?
KenMcFConnect With a Mentor Commented:
You can use the quest AD cmdlets

get-qadcomputer | where{$_.operatingsystem -match "Server"} | select name, operatingsystem | export-csv c:\server.csv

or if they are all in the same OU

get-qadcomputer -searchroot "OU=Servers,DC=Domain,DC=Local"

depending on what information you may need to do a wmi query.

$servers = get-qadcomputer -searchroot "OU=Servers,DC=Domain,DC=Local"
Foreach ($Server in $servers){
gwmi -computer $server -class win32_operatingsystem | select name, producttype
Carl WebsterAuthor Commented:
My problem is I do not know if PS is installed on any server or if I will be allowed to install PS.

I just emailed the customer to find out.  It would be nice if PS is installed or they give me permission to install it.

All I need is the "cn" attribute (according to the test dsquery I ran) which should be the server's hostname.
KenMcFConnect With a Mentor Commented:
if you just need to CN you can install powershell on a workstation that is a member of the domain.

depending on the number of servers you may need to use the -sizelimit switch

get-qadcomputer -sizelimit 0 | where{$_.operatingsystem -match "Server"} | select DN
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

Adam BrownConnect With a Mentor Sr Solutions ArchitectCommented:
This will do pretty much the same thing but utilizes the built in AD Powershell Console for 2008 R2 if you have a DC that uses that.
get-adcomputer -filter * -properties operatingsystem | where
{$_.operatingsystem -match "Server"} | select name, operatingsystem > c:\servers.csv

Open in new window

That should be

get-qadcomputer -sizelimit 0 | where{$_.operatingsystem -match "Server"} | select name
Adam BrownSr Solutions ArchitectCommented:
"My problem is I do not know if PS is installed on any server or if I will be allowed to install PS."
Check if you have a Windows 2008 R2 Domain Controller. If you do, you have the MS AD Powershell Console already.
Carl WebsterAuthor Commented:
KenMcF, where do I get and how to I install the Quest AD cmdlets?

I have two other questions I posted this morning.  This file of server names will be used by another script to list all local groups on each server and the members of each group including nested groups.
Carl WebsterAuthor Commented:
acbrown2010, when I test this on my lab 2008 R2 DC, I get an error saying the term get-adcomputer is not recognized yada yada yada.
Carl WebsterAuthor Commented:
acbrown2010, sorry didn't realize I had to do this:

When the Active Directory module is installed, to start it click Start, point to Administrative Tools, and then click Active Directory PowerShell
Carl WebsterAuthor Commented:
I wound up just using ADFind to do this since the AD and all DCs were 2000.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.