Before proceed, first run the below command to import Active Directory module.
Import-Module ActiveDirectory
Summary
- Get description of all AD computers
- Apply filter to get computers by description
- Get description of computers from specific OU
- Get description for list of computers
Get description of all AD computers
The following command find and list the name and description of all the available computers in Active Directory.
Get-ADComputer -Filter * -Property Name,Description | Select -Property Name,Description
You can also export the details to csv file by using the powershell cmdlet Export-CSV.
Get-ADComputer -Filter * -Property Name,DNSHostName,Description | Select -Property Name,DNSHostName,Description | Export-CSV "C:\AllComputers.csv" -NoTypeInformation -Encoding UTF8
Apply filter to get computers by description
The Get-ADComputer cmdlet supports SQL like filter, we can easily use this filter to get only specific set of AD computers. The below script select all the computers whose description contains the text ‘SVR‘.
Get-ADComputer -Filter 'Description -like "*SVR*"' -Property Name,Description | Select -Property Name,Description
Apply LDAP Filter to get set of AD computers:
If your are familiar with LDAP filter, instead of normal filter, you can also use LDAP filter with to select particular set of AD computers.
Get-ADComputer -LDAPFilter '(Description=*SVR*)' -Property Name,Description | Select -Property Name,Description
Get description of computers from specific OU
We can set target OU scope by using the parameter SearchBase to select computers from specific OU. The following powershell script select all computers from the Organization Unit ‘TestOU’ and export it to CSV file.
Get-ADComputer -Filter * -SearchBase "OU=TestOU,DC=TestDomain,DC=com"` -Property Name,DNSHostName,Description | ` Select -Property Name,DNSHostName,Description | ` Export-CSV "C:\TestOUComputers.csv" -NoTypeInformation -Encoding UTF8
Get description for list of computers
The below powershell script gets description for list of AD computers. First create the text file computers.txt which includes one computer name in each line. You will get the name and description in the csv file ADComputers.csv.
Get-Content C:computers.txt | Get-ADComputer -Property Name,Description |` Select -Property Name,Description |` Export-CSV C:ADComputers.csv -NoTypeInformation -Encoding UTF8