November PowerShell One-liner

[This month’s SAPIEN newsletter offered this one liner I thought I’d share with the rest of you].

The following one line PowerShell expression should show you who is logged on to a specific server and desktop and for how long. Most logon sessions use a single instance of Explorer.exe, although it is possible for a user to manually start additional instances of Explorer.exe.

The KernelMode and UserMode times are in seconds. Because this is an object, you can pipe it to other cmdlets to sort, filter, export or convert. If you have comments or questions about this or anything else PowerShell, please visit the forums at ScriptingAnswers.com.

Bas, it looks like you aren’t getting a connection to the server so the rest of the code is erroring out. If you can, would you please post something in the PowerShell forum at ScriptingAnswers.com? It will be much easier for me to help you in that setting than going back and forth with blog comments.

The connection is to the local machine. It was to test if that was working.But I cannot even reconstruct that error…

But I found that before “$now=Get-Date” an Expression Error is found. And placed an ; there and tried putting an , there. this both solved the “Unexpected token ‘now’ in expression or statement.” but doesn’t let me run the script. I posted in the forum : http://www.scriptinganswers.com/forum2/forum_posts.asp?TID=2376