Solved

Powershell pipeline question.

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Microsoft Windows Server Update Service (WSUS) is free for everyone, but it lacks of some desirable features like send an e-mail to the administrator with the status of all computers on the WSUS server. This article is based on my PowerShell script …
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…

863 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