S.Mahmood
S.Mahmood

Reputation: 151

AD users that have specific word in the description field via Powershell

I am new to PowerShell and I am trying to extract username and name of users that contain a word or specific words in the description field of an AD user.

In the description field we have added user job titles and I am trying to search for specific job titles to display full names and usernames.

What I have gathered from my quick googling is this:

Get-ADUser -Filter * -Properties Description | Select Name,SamAccountName

This displays all AD users with name and username details.

I believe this area I need to change is the -Filter but when I try something like this the command fails

Get-ADUser -Filter -like "developer" -Properties Description | Select Name,SamAccountName

This is probably going to be pretty straightforward for a powershell guy but I am struggling here.

Update to the command

Get-ADUser -Properties Description -Filter 'Description -like "developer"' | Select Name,SamAccountName

Nothing is getting outputted after I enter the command.

Further update the command that worked for me was:

Get-ADUser -Properties Description -Filter 'Description -like "*developer*"' | Select Name,SamAccountName

Upvotes: 0

Views: 3345

Answers (1)

Avshalom
Avshalom

Reputation: 8889

Using -Filter Parameter:

Get-ADUser -Properties Description -Filter {Description -like "developer"}
OR
Get-ADUser -Properties Description -Filter 'Description -like "*developer*"'

Using Where-Object

Get-ADUser -Properties Description -Filter * | ? Description -match "developer"

Add your Final Select at the end of the pipeline if you just need this specific properties:

| Select Name,SamAccountName,Description

Upvotes: 2

Related Questions