Powershell Log Off Remote Session

前端 未结 11 1223
情话喂你
情话喂你 2020-12-02 13:15

I am trying to formulate a Powershell command to remotely log off a user. We have a terminal server with a very unstable program that sometimes locks sessions. We have to re

11条回答
  •  暖寄归人
    2020-12-02 14:04

    I've modified Casey's answer to only logoff disconnected sessions by doing the following:

       foreach($Server in $Servers) {
        try {
            query user /server:$Server 2>&1 | select -skip 1 | ? {($_ -split "\s+")[-5] -eq 'Disc'} | % {logoff ($_ -split "\s+")[-6] /server:$Server /V}
        }
        catch {}
        }
    

提交回复
热议问题