Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get-IdleTime fails to parse disconnected sessions #11

Closed
tobraha opened this issue Apr 7, 2021 · 1 comment · Fixed by #16
Closed

Get-IdleTime fails to parse disconnected sessions #11

tobraha opened this issue Apr 7, 2021 · 1 comment · Fixed by #16
Assignees
Labels
bug Something isn't working

Comments

@tobraha
Copy link
Contributor

tobraha commented Apr 7, 2021

When a session is disconnected ("DISC") the SESSIONNAME field is empty and is not properly parsed:

PS C:\WINDOWS\system32> quser
 USERNAME              SESSIONNAME        ID  STATE   IDLE TIME  LOGON TIME
 jsmith                                    1  Disc        14:36  3/24/2021 9:46 AM

This fails to properly tokenize the output and parse the fields:

quser /server:$CN_Item |
    Select-Object -Skip 1 |
    ForEach-Object {($_ -replace '\s{2,}', ',').Trim()} |
    ConvertFrom-Csv -Header $Header

I've been trying to find a way to use something other than 'query user' or 'quser' to get this info. Apparently it queries the Terminal Services API (? Can't find the reference I thought I saw yesterday... ☹️ ) to get this info.

How else could we find user idle time??

@tobraha tobraha added the bug Something isn't working label Apr 7, 2021
@tobraha
Copy link
Contributor Author

tobraha commented Apr 7, 2021

I'm wondering if we could cherry pick some of the functionality from PSReflect-Functions to accomplish this. Looks like it uses wtsapi32 to query user sessions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants