I’m in the middle of MS PowerShell training and today my colleague, Marcin, went into strange issue when working in WMI. Basically when he got two commands with select at the end of each he was getting only properties from first object collection. Second looked empty, or rather full of blanks. After we tried several things we discovered, that this is not WMI, nor second select that is causing this strange behaviour. Try yourself:
Get-Process | select Id Get-Service | select Name
Result? List of Ids and than many empty lines. This won’t happen if you try to launch each command separately. It won’t happen if you redirect first command to Out-Default (something I was sure was ALWAYS done automagically). It get’s even worse if you try to format output of second command, try:
Get-Process | select Id -First 2 Get-Service | Format-List
You will get error similar to one you get when you e.g. try to sort after you format:
The object of type "Microsoft.PowerShell.Commands.Internal.Format.FormatStartData" is not valid or not in the correct sequence.
This is likely caused by a user-specified "format-list" command which is conflicting with the default formatting.
I wonder if you walked into the same issue? Maybe it is already logged on connect? The only reasonable workaround I found so far is intentional redirection to out-default. What is most surprising to me is that I have never noticed that behaviour. And I select things quite often… Maybe that’s because I usually consume them and the real problem is selects left alone in the pipeline… 😉
PS: It was tested on W2K8R2 and Win7.