Answer the question
In order to leave comments, you need to log in
How to get a list of values into a variable from the results of a command in PowerShell?
The ultimate goal is to make sure that all users have logged out of their sessions on the terminal server.
It was decided to use the qwinsta utility command.
We execute the following command in PS : We get the qwinsta /server:DC1
result:
I would like to get the IDs of all sessions in an array for further analysis: we are looking for values other than 0, 1, 65536 in the array. If we find it, it means that not all users have completed their sessions on the server yet.
I specifically described the problem in full, as perhaps someone will suggest a more beautiful solution.
Thank you.
Answer the question
In order to leave comments, you need to log in
1. In the first line, find where the ID ends
2. Cut off the rest of the lines, and find the number at the end
PS> $out = (qwinsta)
PS> $len = ($out | select -First 1 | ? { $_ -match '.*(ID)' } | % { $matches[0].Length })
PS> $out | select -skip 1 | % { $_.Substring(0, $len) } | ? { $_ -match '(\d+)$' } | % { $matches[1] }
0
2
65537
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question