Your output may vary

While I was testing the new PowerShell enabled RSEE service, I used one of the many files our users send us to illustrate one thing or another or to report a bug. Using real world script files rather than some “clean” in-house samples makes for a better test as far as I am concerned.

(Disclaimer: Any such script containing personal information or access information of any kind is either made to be anonymous or deleted.)

While testing, I noticed that get-process produced a list style output rather than the familiar table that get-process normally emits. An hour or two of investigating this brought the script down to two lines:

get-date
get-process

Running those two lines from the shell worked fine, but using them inside a script “getprocesses.ps1” and running them with
./getprocess.ps1
produces the different output.

The original script was far more complex, issuing a dated report about checking server processes running and restarting them if so required, but trimming it down to these two lines is sufficient to see the the effect.

As it turns out, if you simply use get-date or any other of an assorted list of cmdlets, the output of get-process reverts back to a list rather than a table. Other cmdlets emitting tables by default are affected as well and using

get-process | format-table

just results in an error message.

When I asked the original author of the script if he noticed that difference in output he responded as follows:

“Yes, I noticed. As a matter of fact, I banged my head against this for quite some time but I found no way to make get-process print a table again. I finally gave up and learned to live with the list output.”

I am hoping that knowing this will prevent some “head banging” for you guys out there. Keep in mind that the output of your cmdlets in a script may be different from what you see when using them in the shell. It seems it depends on how you mix them together.