Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Powershell pipeline question.

Posted on 2013-10-31
1
Medium Priority
?
209 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Creating Active Directory Users from a Text File

If your organization has a need to mass-create AD user accounts, watch this video to see how its done without the need for scripting or other unnecessary complexities.

Question has a verified solution.

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

A procedure for exporting installed hotfix details of remote computers using powershell
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…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

704 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