This script will find all Server 2008 (and Server 2008 R2) machines on your domain:
001
002 003 004 005 006 007 008 009 010 011 012 013 |
$objDomain = [ADSI]”
$objSearcher = New-Object System.DirectoryServices.DirectorySearcher $objSearcher.SearchRoot = $objDomain $objSearcher.Filter = "(&(objectCategory=computer)(operatingsystem=*Server 2008*))" $objSearcher.PageSize = 1000 $colProplist = "*" foreach ($i in $colPropList){$objSearcher.PropertiesToLoad.Add($i)} $colResults = $objSearcher.FindAll() $Server2008 = @() foreach ($objResult in $colResults) { $Server2008 += $objResult.Properties.name } |
You can change the operatingsystem= line to gather the OS you are interested in.
#1 by Dan Dill on April 8, 2010 - 19:23
Hello,
For some reason this didn’t work for me when I copied the code. I edited the $objDomain variable so not sure what was going on there. I ended up writing the same thing myself which worked for me as I just needed to pull the names of the machines. I think your script here pulls more details. Anyways, my code I posted here just fyi:
http://danstechnotes.blogspot.com/2010/04/powershell-script-to-find-specific-os.html
#2 by karlmitschke on April 13, 2010 - 15:21
I like your use of a function – I may modify mine to allow the same.
Did you get an error running my script?