Arbelac Arbelac - 2 months ago 9x
PowerShell Question

Getting AD users having a specific keyword within description field in AD

I want to get all of those users starting with a specific keywords in AD User Description field using PowerShell.
Keyword: Could not execute powershell

Import-Module ActiveDirectory

Get-ADUser -Filter * -SearchBase 'OU=contoso, DC=contoso, DC=local' - Properties Description | select -expand name,distinguishedname,description | Export-Csv -path C:\description.csv -NoTypeInformation

Last Update :

Get-ADUser -Properties Description -Filter 'Description -like "*Could not execute powershell*"' -SearchBase 'OU=contoso, DC=contoso, DC=local' |
select name,distinguishedname,description |
Export-Csv -path C:\description2.csv -NoTypeInformation


This is an easy task using the -filter option that you can use with get-aduser.

For more info how to filter:

Under the filter bit

 Get-ADUser -Properties Description -Filter {Description -like $Description} -SearchBase 'OU=contoso, DC=contoso, DC=local' | select Name, DistinguishedName, Description | Export-Csv -path C:\description2.csv -NoTypeInformation