【发布时间】:2021-09-30 02:41:41
【问题描述】:
我正在尝试创建一个脚本,该脚本将根据用户名和计算机 ID 远程注销用户。有没有其他人遇到过这个问题?仅当我尝试注销不是我自己的计算机的其他人时才会发生这种情况。
#Target User
$userName = ''
#Target Computer
$computer = ""
#Finding session ID
$sessionId = ((quser /server:$computer | Where-Object { $_ -match $userName }) -split ' +')[3]
#Logging off user
Invoke-RDUserLogoff -HostServer $computer -UnifiedSessionId $sessionId
quser : Error 0x000006AB enumerating sessionnames
At line:8 char:16
+ $sessionId = ((quser /server:$computer | Where-Object { $_ -match $us ...
+ ~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (Error 0x000006A...ng sessionnames:String) [], RemoteException
+ FullyQualifiedErrorId : NativeCommandError
Error [1707]:The network address is invalid.
【问题讨论】:
-
如果您的目标是当前计算机,请尝试在命令行中省略
/server:$computer。
标签: powershell security powershell-2.0 powershell-3.0