Solved

Powershell pipeline question.

Posted on 2013-10-31
1
203 Views
Last Modified: 2013-11-16
Hi,

I am trying to understand how why the two bits of code return extra columns

if I execute

$a = get-process
$b = $a | select-object $_
$b

Open in new window


I get the following columns displayed:

Handles  NPM(K)    PM(K)      WS(K) VM(M)   CPU(s)     Id ProcessName  

However if I want to add a custom column to the object:

The only code I can get to work is something like this.


$a = Get-Process
$b = $a | select-object @{Name="Custom1";Expression={"Test"}},*
$b

Open in new window


However this outputs all of the properties. How can I pass the pipeline
from the $a and only include the default properties PSStandardMembers.

I realize I could just change the * to list the fields that I want
but I can curious to see if there another way to do what I want.

So I can understand the pipeline more.

Thanks,

Ward.
0
Comment
Question by:whorsfall
1 Comment
 
LVL 16

Accepted Solution

by:
Dale Harris earned 500 total points
ID: 39613582
I think it's more of a hack, but you can return the default property set like this:

$Defaults = $a.psstandardmembers.defaultdisplaypropertyset.referencedpropertynames

Then add anything additional you want here:
$Defaults += "MachineName"

Now when you do this, it works:
$a | select $Defaults

And to make it appear a little cleaner:

$a | select $defaults | ft


HTH,

Dale Harris
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Hi all.   The other day I had to change the passwords for a bunch of users on the fly. Because they were so many, I decided to do it in an automated way and I would like to share it with you all.   If you are not doing it directly in a Domain Co…
Synchronize a new Active Directory domain with an existing Office 365 tenant
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now