PowerShell Version 4 New Feature: A UserName Property Has Been Added To Get-Process Output Objects

Thanks to a tweet from Mark Schill, I discovered that Get-Process now has an IncludeUserName parameter in PowerShell version 4:

ps4-getprocess-tweet.png

This means no more having to use WMI to determine what processes are being run by which users:

ps4-getprocess1.png

For those of us who work in a terminal services environment, this is a really big deal.

I do find it odd that it was added via a switch parameter instead of just making it another property. It kind of reminds me of how the Active Directory cmdlets are implemented. My initial guess was there must be some additional overhead in retrieving this information and they didn't want to incur the resource cost unless the user was intentionally trying to retrieve this information.

This one additional UserName property only shows up in the output when the IncludeUserName parameter is specified:

ps4-getprocess2.png

One thing that's a little disappointing to see is the IncludeUserName parameter can't be used with the ComputerName parameter to target remote computers directly without using PowerShell remoting to receive this information. That's probably why it's implemented as a switch parameter. There must be an issue where it doesn't work natively against remote computers so it was implemented as a switch parameter so it could excluded from the parameter sets that include a ComputerName parameter:

ps4-getprocess3.png

Why is this a big deal? I should have no issue installing PowerShell version 4 on my workstation as soon as it's released, but I have machines that won't run PowerShell version 4 and it may take a while to get approval to install PowerShell version 4 on the ones it will run on. I was hoping to be able to target remote computers with this cmdlet from my workstation without the requirement of needing PowerShell version 4 installed on the remote computers. This is still possible, but in that scenario, the cmdlet will work just like it did in PowerShell version 2 and 3 which means no user information will be returned as it will be using one of the first three parameter sets shown in the previous image.

I double checked to make sure this wasn't a mistake in the help documentation and sure enough, the IncludeUserName parameter does not work when also specifying the ComputerName parameter:

ps4-getprocess4.png

I guess it's back to using WMI in that scenario after all.

Same thing applies for the IncludeUserName parameter and FileVersionInfo or Module parameters. Since they live in different parameter sets, they're mutually exclusive.

ps4-getprocess5.png

This isn't really an issue with these other parameters though since the information is there and you can simply select it from the pipeline as shown in the following example where I've returned the information for the IncludeUserName and what would have been returned for the FileVersionInfo parameter manually:

ps4-getprocess6.png

It makes me wonder why those two parameters can't be used together if I can return the information as in the example in the previous image? All of this is subject to change of course since this information is based off of PowerShell version 4 running on a preview version of Windows Server 2012 R2.

µ