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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Dale HarrisProfessional 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
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
Simplify Active Directory Administration

Administration of Active Directory does not have to be hard.  Too often what should be a simple task is made more difficult than it needs to be.The solution?  Hyena from SystemTools Software.  With ease-of-use as well as powerful importing and bulk updating capabilities.

Giovanni HewardCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Active Directory

From novice to tech pro — start learning today.