Finding a computer in the AD using #Powershell

So I need to search the AD today for computer objects to see if a description has been set.

$Domain = ([System.DirectoryServices.ActiveDirectory.Domain]::GetCurrentDomain()).Name
$Dom  = “LDAP://DC=” + $Domain.Replace(“.”,”,DC=”)
$strComputer = “<computer2search4>”
$strFilter  = “(cn=$strComputer)”
$Root       = New-Object DirectoryServices.DirectoryEntry $Dom
$selector   = New-Object DirectoryServices.DirectorySearcher
$selector.PageSize    = 1000
$selector.Filter      = $strFilter
$selector.SearchRoot  = $root
$selector.SearchScope = “Subtree”
$Objs = $selector.findall()
$Objs.count

 

The results are in the variable $Objs

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: