The following Script stub will query AD for all active Windows 2008 Servers (can be tweaked) and create a collection of those servers.
# ######################################################################
# - Section for gathering Windows Server Information ...
# -- Define Global Variables --
$strCategory = "computer"
$strOS = "*2008*"
# -- Get AD information --
$objDomain = New-Object System.DirectoryServices.DirectoryEntry
$objSearcher = New-Object System.DirectoryServices.DirectorySearcher
$objSearcher.SearchRoot = $objDomain
$objSearcher.Filter = "(&(objectCategory=$strCategory)(operatingSystem=$strOS)(name=*)(!(userAccountControl:1.2.840.113556.1.4.803:=2)))"
# - define Attributes to find -
$colProplist = "name"
foreach ($i in $colPropList){$return=$objSearcher.PropertiesToLoad.Add($i)}
# - Find all Computers that fit the Search profile
$colResults = $objSearcher.FindAll()
# -- Format the Output --
# convert Collection into an array
$servers = @()
foreach ($objResult in $colResults)
{
$servers = $servers + $objResult.Properties.item("name")
}
# Sort Server Names
$servers = $servers | sort-object
# ######################################################################
# - Section for gathering Windows Server Information ...
# -- Define Global Variables --
$strCategory = "computer"
$strOS = "*2008*"
# -- Get AD information --
$objDomain = New-Object System.DirectoryServices.DirectoryEntry
$objSearcher = New-Object System.DirectoryServices.DirectorySearcher
$objSearcher.SearchRoot = $objDomain
$objSearcher.Filter = "(&(objectCategory=$strCategory)(operatingSystem=$strOS)(name=*)(!(userAccountControl:1.2.840.113556.1.4.803:=2)))"
# - define Attributes to find -
$colProplist = "name"
foreach ($i in $colPropList){$return=$objSearcher.PropertiesToLoad.Add($i)}
# - Find all Computers that fit the Search profile
$colResults = $objSearcher.FindAll()
# -- Format the Output --
# convert Collection into an array
$servers = @()
foreach ($objResult in $colResults)
{
$servers = $servers + $objResult.Properties.item("name")
}
# Sort Server Names
$servers = $servers | sort-object
Comments
Post a Comment