Extract session ID from psexec / PowerShell query user command

后端 未结 1 1957
无人共我
无人共我 2021-01-23 23:39

I\'m writing a PowerShell script to find out the session ID of the active user at a remote machine, to then launch a program using that session ID. Here is what I have so far.

1条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-24 00:00

    Try this:

    $id = $results | ? { $_ -match '(\d+)\s+Active' } | % { $matches[1] }
    

    The regular expression (\d+)\s+Active will match the keyword "Active" preceeded by a number and the subsequent loop returns the first submatch (i.e. the number).

    0 讨论(0)
提交回复
热议问题