Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Powershell pipeline question.

Posted on 2013-10-31
1
Medium Priority
?
210 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 2000 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

The Nano Server Image Builder helps you create a custom Nano Server image and bootable USB media with the aid of a graphical interface. Based on the inputs you provide, it generates images for deployment and creates reusable PowerShell scripts that …
My attempt to use PowerShell and other great resources found online to simplify the deployment of Office 365 ProPlus client components to any workstation that needs it, regardless of existing Office components that may be needing attention.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…

783 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