I have a small script that will help users in our environment shadow the sessions from other users in the facilities (I work at the corporate office, corporate users need the ability to shadow other user's sessions along different sites)
So I've got this:
$servers = "server1, server2, server3, server4, server5"
#search for user in servers farm
foreach ($server in $servers) {
$results = & qwinsta.exe $userid /server:$server
if ($results -ne $null) {
write-host "User found in $server"
$serverfound = $server
write-host $results[1]
$sessionid = $results[1] | Where-Object { $_ -is 0..99}
write-host "Session ID is: $sessionid"
}
}
However, I can't get it to grab the session id from the result, this is the output of the script:
Please wait while we search for x2adm on the RDSfarm Servers
User found in server5
rdp-tcp#0 x2adm 2 Active
Session ID is:
I am trying to simply grab the number in the output and assign it to $sessionid so that I can fully automate the shadowing process.
Any help will be appreciated. Thanks in advance.