Skip to content

Instantly share code, notes, and snippets.

@Slusho
Created November 28, 2017 16:32
Show Gist options
  • Save Slusho/b5bd1245cfb38dbf3ed7b5b682b653a1 to your computer and use it in GitHub Desktop.
Save Slusho/b5bd1245cfb38dbf3ed7b5b682b653a1 to your computer and use it in GitHub Desktop.
Get computer description from AD
$DomainName = 'LDAP://OU=Test Computers,DC=Contoso,DC=Com'
$Root = New-Object DirectoryServices.DirectoryEntry $DomainName
$objSearcher = New-Object DirectoryServices.DirectorySearcher
$objSearcher.SearchRoot = $Root
$objSearcher.SearchScope = "SubTree"
$objSearcher.Filter = "(objectCategory=computer)"
$colResults = $objSearcher.FindAll()
foreach ($objResult in $colResults)
{
$objComputer = $objResult.Properties
$computer = $objResult.GetDirectoryEntry()
$name = [string]$computer.name
$Description = [string]$computer.description
echo $Description
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment