Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PowerShell command to filter records with multiple values

Tags:

powershell

I am working with PowerShell commands. I want to filter records with one field name description. I successfully filter with one description named "school". My command is:

Get-ADuser -filter {(Description -eq "school")} -Properties * | select *

But I want to filter records with multiple values of description like "school", "college", etc. How will this be possible?

like image 846
user3792844 Avatar asked Mar 28 '26 05:03

user3792844


1 Answers

You could use an -or statement:

Get-ADuser -filter {(Description -eq "school") -or (Description -eq "college")} -Properties * | select *

Or you could create an array and filter the results, although this is filtering after the query executes, so it may take longer. It would make sense to try and apply a filter to Get-AdUser before passing it through where-object:

@filter = @("school", "college")
Get-ADuser -Properties * | where-object{@filter -contains $_.Description} | select *
like image 111
David Martin Avatar answered Mar 29 '26 20:03

David Martin