我们有3台终端服务器,最终每天都要启动用户。我对PS完全陌生并且学习了我所能做的,但是在这里遇到问题。确定使用哪个TS用户,然后用备用凭证强制注销用户?
脚本提示输入用户名,然后搜索3台服务器,找到它们所在的位置并给我他们的会话ID。然后,我必须输入服务器#和会话ID并运行Invoke-RDUserLogoff命令,但问题是,我需要将该命令作为我的域管理员帐户运行......我的标准用户帐户没有权限执行此操作。
也许有甚至完全不同/更好的方式来做到这一点?
在此先感谢。
$user = read-host -prompt "What is the USERNAME you need to disconnect?"
$term1 = qwinsta /server:ts1 | findstr "$user"
$term2 = qwinsta /server:ts2 | findstr "$user"
$term3 = qwinsta /server:ts3 | findstr "$user"
write-host TS1
$term1
write-host TS2
$term2
write-host TS3
$term3
$term = read-host -prompt "Which terminal server is the user on? (1, 2, or 3?)"
$id = read-host -prompt "To logoff the user, enter their ID #:"
Invoke-RDUserLogoff -HostServer ts$term -UnifiedSessionID $id -Force
使用具有足够权限的帐户打开PowerShell窗口,然后运行脚本。 –