wiktor
wiktor

Reputation: 191

Powershell system-object - select property with "filter"

Lets say I have an object named something:

Name                                           : name1
Group                                          : group1

Name                                           : name2
Group                                          : group2

Name                                           : name3
Group                                          : group1

I can access all names by:

$something | Select -ExpandProperty "Name";

it returns: name1 name2 name3

How would I select only the names from group1? so it returns

name1 name3

Something like:

$something | Select -ExpandProperty "Name" -Where [Group -eq 'group1'];

Upvotes: 1

Views: 495

Answers (1)

Mathias R. Jessen
Mathias R. Jessen

Reputation: 174825

Use the Where-Object cmdlet to filter:

$something |Where-Object Group -eq 'group1' |Select -ExpandProperty "Name"

Upvotes: 4

Related Questions