0

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

S.Mahmood
  • 129
  • 11
  • `Get-ADUser -Filter "Description -Like '*developer*'" -Properties Description`; this also may take a while depending on how many users you have, so I'd recommend narrowing down the search to an OU. – Abraham Zinala Feb 07 '22 at 12:40
  • Thanks your comment helped my fix it. – S.Mahmood Feb 07 '22 at 12:58

1 Answers1

1

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
Avshalom
  • 8,657
  • 1
  • 25
  • 43
  • Hi thanks for your help I tried the -filter parameter: Get-ADUser -Properties Description -Filter 'Description -like "developer"' | Select Name,SamAccountName nothing gets outputted so I tried the where-object parameter Get-ADUser -Properties Description * | ? Description -match "developer" this fails cannot find an object with identity '*' – S.Mahmood Feb 07 '22 at 12:44
  • Update your select... add description.. check in the answer – Avshalom Feb 07 '22 at 12:50
  • Sorry I was my fault I was missing the additional * after developer so I entered * developer not * developer * thanks for your help on this it fixed the command. – S.Mahmood Feb 07 '22 at 12:57