• Status: Solved
  • Priority: Low
  • Security: Public
  • Views: 38
  • Last Modified:

Powershell: filter result on columns?


How can I achieve this (want to filter out status out of get-service but do not want to use get-service | select-object name,displayname

 get-service | Where-Object -NE status

Thanks for your input.
  • 2
1 Solution
You can't remove properties from an object.
In other words: if you want to get rid of the Status property, you're going to have to use Select-Object.
What is it exactly that you want to achieve, and what's wrong with Select-Object?
Perhaps you mean you don't want to have to specify all the properties you do want with Select-Object?
get-service | select-object * -excludeProperty Status

Open in new window

janhoedtAuthor Commented:
Thanks for the input. I have an output which belongs on input.
Scan-Network -port x,y,z gives

HostName Portx Porty Portz ThenAnObjectIdonotWant01 ThenAnObjectIdonotWant02

So I want select-object  HostName, Portx,Porty,Portz but extra ports can be added and I won't know them beforehand.
What I DO know is that I don't want is ThenAnObjectIdonotWant01, ThenAnObjectIdonotWant02 so wanted to DE-select them.
Select-Object's accepts wildcards both for Property and ExcludeProperty (and even ExpandProperty, provided it matches only one property).
If you only want Hostname and anything starting with Port, you just do
Scan-Network -Port x, y, z | Select-Object -Property HostName, Port*

Open in new window

Or to exclude properties matching a pattern:
Scan-Network -Port x, y, z | Select-Object -Property * -ExcludeProperty DropThisProperty, ThenAnObjectIdonotWant*

Open in new window

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Protect Your Employees from Wi-Fi Threats

As Wi-Fi growth and popularity continues to climb, not everyone understands the risks that come with connecting to public Wi-Fi or even offering Wi-Fi to employees, visitors and guests. Download the resource kit to make sure your safe wherever business takes you!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now