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
最佳解决方案:一名保安护送人员出去......
第二个最佳解决方案:
Run Code Online (Sandbox Code Playgroud)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.
我为此编写了一个基本的批处理脚本。我需要一些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)
不完全基于 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 来查找它。
| 归档时间: |
|
| 查看次数: |
117169 次 |
| 最近记录: |