Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

Can someone explain, why this ( powershell 2.0 )

$wmi=Get-WmiObject Win32_UserProfile
$wmi|select *;
$wmi|select SID;
$wmi|select LocalPath;

gives expected results ( selected everything, then selected SIDs, then LocalPaths), while these two gives

$wmi=Get-WmiObject Win32_UserProfile
$wmi|select LocalPath;
$wmi|select SID;
$wmi|select LocalPath;

LocalPaths, nothing, LocalPaths

Get-WmiObject Win32_UserProfile|select SID;
"separator";
gwmi win32_UserProfile|select LocalPath;
"separator"
gwmi Win32_UserAccount|select *;

SIDs, nothing, SIDs again Is there only one instance of select ?

share|improve this question
    
"...while these two" what? What are you asking? –  August Feb 7 '13 at 20:07
    
repaired it, busy night yesterday –  Denwerko Feb 8 '13 at 20:16
    
I do not see the same behavior. Copy/pasting into a v2 PowerShell session here produces no empty values. What do you get for $wmi.Count and ($wmi | select SID).Count? –  jscott Feb 8 '13 at 20:59
    
outputs of all three commands and counts that you requested are here pastebin.com/bQtUzCxQ . –  Denwerko Feb 8 '13 at 21:39
add comment

1 Answer

up vote 0 down vote accepted

You're running into a weird edge case of how the formatting of output in powershell works. Please see this description of the issue from Jeffrey Snover.

I can only reproduce this behavior when running the commands all on one line like so:

$wmi=Get-WmiObject Win32_UserProfile; $wmi | select localpath;$wmi|select SID; $wmi | select localpath

This must be (speculating here) because the entire line is submitted to Out-Default as a batch; if you run each command individually, you don't see this behavior.

But with one call to Out-Default, it first sees the Selected.System.Management.ManagementObject with one property, 'LocalPath', so it creates a table with one column, for 'LocalPath.' Once you get some Selected.System.ManagementObjects with a 'SID' property, they appear in the table as nulls, because their 'LocalPath' property (the only one Format-Table knows to display) is null.

This problem doesn't happen in the first example because the 'select *' causes Out-Default to choose Format-List as the formatter, which is much less lossy.

I hope this helps -- the blog post I linked explains it very well.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.