Solved

Powershell pipeline question.

Posted on 2013-10-31
1
206 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

Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I thought I'd write this up for anyone who has a request to create an anonymous whistle-blower-type submission form created using SharePoint 2010 (this would probably work the same for 2013). It's not 100% fool-proof but it's as close as you can get…
The following article is intended as a guide to using PowerShell as a more versatile and reliable form of application detection in SCCM.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

820 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