Saturday 14 September 2019

Powershell get a value from 'query user' and not the headers etc

Task, get the ID from the query user command, I'm trying to get the ID value from the the command 'query user',


Example:PS>  query user

USERNAME SESSIONNAME ID STATE IDLE TIME LOGON TIME

>administrator rdp-tcp#0 3 Active . 04/25/2013 08:43

I'm trying to use psexec and attach to the session.


psexec \\\pc -i sessionid somecommand

how would I go about getting the ID and only the ID from the above query? this is what I've tried so far, among other things...


PS>  query user |Select-Object $_.ID

USERNAME SESSIONNAME ID STATE IDLE TIME LOGON TIME

>administrator rdp-tcp#0 3 Active . 04/25/2013 08:43

I would think this is easy but apparently I am having a brain fart, ideally I like to do this:


$IDValue = query user | Get_the_ID_somehow

psexec \\\pc -i $IDValue somecommand..

thanks in advance.

No comments:

Post a Comment

How can I VLOOKUP in multiple Excel documents?

I am trying to VLOOKUP reference data with around 400 seperate Excel files. Is it possible to do this in a quick way rather than doing it m...