Home > OS >  Powershell system-object - select property with "filter"
Powershell system-object - select property with "filter"

Time:08-31

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'];

CodePudding user response:

Use the Where-Object cmdlet to filter:

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