-1

I have a collection of about 15 Remote Desktop Sessions that I need to be able to log off by name. I know I could do it by Session ID, but that changes, so I can't script that to happen several times a day. The username and the IP address never change. Is there a way I can do this in PowerShell?

Thanks! Randy

  • http://stackoverflow.com/questions/18192746/powershell-log-off-remote-session ? Get session ID from user name, then logoff session with session ID ? – sodawillow Nov 09 '15 at 15:29

1 Answers1

0

You could try this (inspired from this) :

$inventory = @(
    @{ ip = "210.987.654.321"; user = "admin01" }
    @{ ip = "123.456.789.012"; user = "admin02" }
)

foreach($server in $inventory) {
    $sessionID = ((quser /server:$($server.ip) | ? { $_ -match $($server.user) }) -split ' +')[3]
    logoff $sessionID /server:$($server.ip)
}
Community
  • 1
  • 1
sodawillow
  • 12,497
  • 4
  • 34
  • 44