Skip to content

Listing Computer Objects with Powershell

2009 October 13
by admin

Have you ever wanted to get a simple output of all the computer objects in active directory? This is a fairly simple task with Powershell, recently I wanted to output all computer objects and the attributes that associated with them for use in a tree structured menu. Below is the script that I created, (can only dump 1000 entries at a time)

$strFilter = "(&(objectCategory=Computer))"
$objDomain = New-Object System.DirectoryServices.DirectoryEntry
$objSearcher = New-Object System.DirectoryServices.DirectorySearcher
$objSearcher.SearchRoot = $objDomain
$objSearcher.PageSize = 1000
$objSearcher.Filter = $strFilter
$objSearcher.SearchScope = "Subtree"
$computerObjects = $objSearcher.FindAll() | foreach {
    $name = [String]$_.Properties.cn
}
$name
No comments yet

Leave a Reply

Note: You can use basic XHTML in your comments. Your email address will never be published.

Subscribe to this comment feed via RSS