script discovery of all server 2003 boxes in a specific OU

I have been asked to discover the hostnames of all the 2003 Server systems in a specific OU. I wanted to output to a text file. Is there a easy way with Powershell or VBS that you might suggest?
Thank you!
JohnD
LVL 1
John DarbyPMAsked:
Who is Participating?
 
Giovanni HewardConnect With a Mentor Commented:
Actually, it appears this is what you're looking for...

 
dsquery * "OU=Domain Controllers,DC=Contoso,DC=Com" -filter "(&(objectCategory=computer)(operatingSystem=*2003*))"

Open in new window


Enjoy! :)
0
 
Dale HarrisConnect With a Mentor Professional Services EngineerCommented:
I would use Quest Powershell Commandlets found here:
http://www.quest.com/powershell/activeroles-server.aspx

Then using the command "Get-QADComputer" you can specify the OU  you want to target.

Save that to a variable, then do your "discovery" on them for OS type, etc.

$OU = "OU=Servers, DC=Contoso"
$Servers = Get-QADComputer -OU $OU
Foreach ($Server in $Servers){
$BIOS = Get-WMIObject Win32_BIOS -Computer $Server
$SN = $BIOS.serialnumber
$Win32OS = gwmi Win32_OperatingSystem -Computer $Server
$OS = $Win32OS.version
$ComputerSystem = gwmi Win32_ComputerSystem -Computer $Server
$Name = $ComputerSystem.name
}


Something like that, you get the idea.  Very easy to implement.  I've used long and short versions of certain commands, etc.  Remember that you can pull out much more than just the Serial Number, OS Version, and Name, so you can get most of what you want using those three WMI commands.

Good luck!

Dale Harris
0
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

 
Dale HarrisProfessional Services EngineerCommented:
I forgot to include the output to text file portion:

$OU = "OU=Servers, DC=Contoso"
$Servers = Get-QADComputer -OU $OU
Foreach ($Server in $Servers){
$BIOS = Get-WMIObject Win32_BIOS -Computer $Server
$SN = $BIOS.serialnumber
$Win32OS = gwmi Win32_OperatingSystem -Computer $Server
$OS = $Win32OS.version
$ComputerSystem = gwmi Win32_ComputerSystem -Computer $Server
$Name = $ComputerSystem.name
"Server found: $Name `n OS:$OS `n SN:$SN `n Computer Name:$Name" >> "NewServersFound.txt"
}

0
 
John DarbyPMAuthor Commented:
Thank you...I was running afoul the dsquery!
0
 
Giovanni HewardCommented:
Here is the complete solution you're looking for...

You may run as:

example.bat (will search from root)
example.bat OU=Domain Controllers,DC=SBSuGenius,DC=local
example.bat "OU=Domain Controllers,DC=SBSuGenius,DC=local"

Note: You may use spaces in the distinguished name with or without quotes with this solution.

[example.bat]
@echo off
setlocal enabledelayedexpansion
if [%1]==[] (
	set dn=domainroot
) else (
	set dn=%*
	set dn=!dn:"=!
)
for /f "tokens=1 delims=$" %%s in ('dsquery * "!dn!" -filter "(&(objectCategory=computer)(operatingSystem=*2003*))"^|dsget computer -samid^|find /V "samid" ^|find /V "dsget"') do (
	set str=%%s
	set str=!str: =!
	call :log !str!
)
echo Done! Check %userprofile%\desktop\machines.txt
goto :eof

:log
echo Located %*...
title Located %*...
echo %*>>"%userprofile%\desktop\machines.txt"

Open in new window


Enjoy!
0
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.