强制经过身份验证的用户立即注销(紧急情况)

Era*_*iel 27 security active-directory user-management windows-server-2012-r2

在 Active Directory 中,如果您想阻止用户登录,您可以禁用他们的帐户或简单地重置他们的密码。但是,如果您有一个用户已经登录到工作站,并且您需要尽快阻止他们访问任何资源 - 您会怎么做?我说的是一种紧急情况,在这种情况下,一名工人被立即解雇,如果他们没有立即被锁定在网络之外,他们就有造成严重破坏的风险。

几天前,我遇到了一个类似的案例。起初我不知道如何行动。阻止用户访问网络共享很容易,但这还不够。最终,我使用Stop-Computer -ComputerName <name> -ForcePowerShell cmdlet关闭了目标计算机,就我而言,这解决了问题。但是,在某些情况下,这可能不是最佳选择,例如,如果您需要关闭的用户登录在多个工作站或提供重要服务的计算机上,而您无法将其关闭。

远程强制用户立即从所有工作站注销的最佳解决方案是什么?这在 Active Directory 中甚至可能吗?

ETL*_*ETL 21

最佳解决方案:一名保安护送人员出去......

第二个最佳解决方案:

  1. 首先用qwinsta查看会话号:QWINSTA /server:computername
  2. 记下会话 ID。
  3. 然后使用注销命令:LOGOFF sessionID /server:computername。
C:\>qwinsta /?
Display information about Remote Desktop Sessions.

QUERY SESSION [sessionname | username | sessionid]
              [/SERVER:servername] [/MODE] [/FLOW] [/CONNECT] [/COUNTER] [/VM]

  sessionname         Identifies the session named sessionname.
  username            Identifies the session with user username.
  sessionid           Identifies the session with ID sessionid.
  /SERVER:servername  The server to be queried (default is current).
  /MODE               Display current line settings.
  /FLOW               Display current flow control settings.
  /CONNECT            Display current connect settings.
  /COUNTER            Display current Remote Desktop Services counters information.
  /VM                 Display information about sessions within virtual machines.


C:\>logoff /?
Terminates a session.

LOGOFF [sessionname | sessionid] [/SERVER:servername] [/V] [/VM]

  sessionname         The name of the session.
  sessionid           The ID of the session.
  /SERVER:servername  Specifies the Remote Desktop server containing the user
                      session to log off (default is current).
  /V                  Displays information about the actions performed.
  /VM                 Logs off a session on server or within virtual machine. The unique ID of the session needs to be specified.
Run Code Online (Sandbox Code Playgroud)

我为此编写了一个基本的批处理脚本。我需要一些unixtools路径以及psexec.

@ECHO OFF
:: Script to log a user off a remote machine
::
:: Param 1: The machine
:: Param 2: The username

psexec \\%1 qwinsta | grep %2 | sed 's/console//' | awk '{print $2}' > %tmp%\sessionid.txt
set /p sessionid=< %tmp%\sessionid.txt
del /q %tmp%\sessionid.txt
psexec \\%1 logoff %sessionid% /v
Run Code Online (Sandbox Code Playgroud)

  • 是否可以将这两个命令组合成一个自动批处理/powershell 文件?运行一个快速脚本来注销所有会话可能非常有用。 (2认同)

Dav*_*d V 5

不完全基于 AD,但应该做你想做的。

禁用或过期帐户

import-module activedirectory
set-aduser -identity "username" -accountexperationdate "12:09 pm"
Run Code Online (Sandbox Code Playgroud)

或者

set-aduser -identity "username" -enabled $false
Run Code Online (Sandbox Code Playgroud)

然后将用户从他们的机器上注销

shutdown -m "\\computername" -l
Run Code Online (Sandbox Code Playgroud)

注销用户的另一种方法是从管理命令提示符使用内置的 Windows 实用程序

logoff 1 /SEVER:computername
Run Code Online (Sandbox Code Playgroud)

这将从远程计算机上注销会话 ID 1。如果您不知道会话 ID(默认为 1),那么您可以对远程机器使用 quser 来查找它。

  • 默认情况下,`shutdown` 命令实际上并没有关闭,而是 [_logs off the user_](http://technet.microsoft.com/en-us/library/bb491003.aspx)。 (4认同)
  • 我的工作策略通常是这样的:人们被召集到“会议”(终止),而在会议上,帐户被禁用并且会话远程注销(台式机都安装了安全的 VNC 服务器)。 (4认同)
  • 请不要误会我的意思,但您的回答正是我不想要的,我已将所有这些都包含在我的问题中:禁用/过期帐户或更改密码不会强制用户注销,它只会阻止他们登录在 OP 中描述的情况下没有用。 (3认同)