powershell - Select-Object doesn't return object? -



powershell - Select-Object doesn't return object? -

the next code returns expected list.

$groups = ps | grouping name $groups | sort-object name | % { $g = $_.group | measure pm -sum; new-object psobject -property @{ name2 = $_.name; count = $g.count; sum = $g.sum } }

however, next script, utilize select create custom object, returns nothing? read select-object way create psobject?

$groups = ps | grouping name $groups | sort-object name | % { $g = $_.group | measure pm -sum; select -property @{ name = 'name'; look = { $_.name }}, @{ name = 'count'; look = { $g.count }}, @{ name = 'sum'; look = { $g.sum }} }

update: tested on powershell 2.0 , 3.0. behave same.

windows powershell copyright (c) 2012 microsoft corporation. rights reserved. ps h:\> $groups = ps | grouping name ps h:\> ps h:\> $groups | sort-object name | % { >> $g = $_.group | measure pm -sum; >> # new-object psobject -property @{ name2 = $_.name; count = $g.count; sum = $g.sum } >> select -property @{ name = 'name'; look = { $_.name }}, @{ name = 'count'; look = { $g.count }}, @{ name = 'sum'; look = { $g.sum }} >> } >> ps h:\>

the select statement standalone command not receiving input pipeline since within foreach block. you, have pass current pipeline object $_ select statement anything:

$groups | sort-object name | % { $g = $_.group | measure pm -sum; $_ | select -property @{ name = 'name'; look = { $_.name }}, @{ name = 'count'; look = { $g.count }}, @{ name = 'sum'; look = { $g.sum }} }

powershell powershell-v2.0 powershell-v3.0

Comments

Popular posts from this blog

xslt - DocBook 5 to PDF transform failing with error: "fo:flow" is missing child elements. Required content model: marker* -

mediawiki - How do I insert tables inside infoboxes on Wikia pages? -

Local Service User Logged into Windows -