ΩmegaMan
ΩmegaMan

Reputation: 31616

Filter By Literal Column Name

Using a command against my local IIS of gci "IIS:\Sites\My Website" it gets an output where there is a column named Type:

enter image description here

But I am unable to filter by that column such as

| Where-Object {$_.Type -eq 'application'}

because Type is a keyword(?) maybe.

How does one tell the filter to use the literal column name?


Original output generated from the gci command in the Webadministration module:

Import-Module Webadministration

gci "IIS:\Sites\My Website" 

Note that the actual name of the IIS website has to go into "My Website" shown above.

Full command that doesn't not filter out the directory rows of data and only keeps application:

gci "IIS:\Sites\My Website" | Where-Object {$_.Type -eq 'application'}

Upvotes: 1

Views: 554

Answers (2)

T-Me
T-Me

Reputation: 1884

edit: The Type property can be found with $_.nodetype. So the rest of this Answer is not needed


Create your own column name. This way you are able to filter objects by the new one:

| Select-Object YourDesiredColumns,@{Name='NewColumn';Expression={$_.Type}}

Could be like this:

gci "IIS:\Sites\My Website" | Select-Object *,@{Name='Bob';Expression={$_.NodeType}} | Where-Object {$_.Bob -eq 'application'} | ft

Upvotes: 1

user6811411
user6811411

Reputation:

Simulating with data from a here string and ConvertFrom-Csv that's doesn't impose a problem:

$Data = @"
Type,Application
application,ArchiveServices
directory,aspnet_client
"@ | ConvertFrom-Csv

$Data | Where-Object {$_.Type -eq 'application'}
$Data | Where-Object Type -eq 'application'

Upvotes: 1

Related Questions