Powershell Log Off Remote Session

前端 未结 11 1236
情话喂你
情话喂你 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 am sure my code will be easier and works faster.

        $logon_sessions = get-process -includeusername | Select-Object -Unique -Property UserName, si | ? { $_ -match "server" -and $_ -notmatch "admin" }
    
        foreach ($id in $logon_sessions.si) {
            logoff $id
        }
    

提交回复
热议问题