Powershell 如何远程更改登录启用/禁用
将终端服务器上的登录模式更改为禁用时。我经常忘记在结束会话之前重新启用它。Powershell 如何远程更改登录启用/禁用,powershell,powershell-remoting,Powershell,Powershell Remoting,将终端服务器上的登录模式更改为禁用时。我经常忘记在结束会话之前重新启用它。 显然,如果发生更改,我无法重新连接。您可以使用WMIWin32\u TerminalsServices设置来检查和更改TSLogons的状态 Get-WmiObject Win32_TerminalServiceSetting -N "root/cimv2/terminalservices" -computername $_ -Authentication PacketPrivacy 我写了2个函数,在许多计算机上同时
显然,如果发生更改,我无法重新连接。您可以使用WMIWin32\u TerminalsServices设置来检查和更改TSLogons的状态
Get-WmiObject Win32_TerminalServiceSetting -N "root/cimv2/terminalservices" -computername $_ -Authentication PacketPrivacy
我写了2个函数,在许多计算机上同时启用和禁用它
function LogonDisable {
param (
[Parameter(Mandatory=$true,Position=0)]
[Alias("CN")]
[string[]]$ComputerName
)
TRY {
$ComputerName | Select-Object -Unique | %{
$TS_Connector = Get-WmiObject Win32_TerminalServiceSetting -N "root/cimv2/terminalservices" -computername $_ -Authentication PacketPrivacy
$TS_Connector.Logons=1
$TS_Connector.Put()
$TS_Connector.Get()
if ($TS_Connector.Logons -eq 1) {
"OK"
} else {
"Error"
}
}
}#TRY
CATCH {
Write-Warning -Message "$($Error[0].Exception)"
}
}
function LogonEnable {
param (
[Parameter(Mandatory=$true,Position=0)]
[Alias("CN")]
[string[]]$ComputerName
)
TRY {
$ComputerName | Select-Object -Unique | %{
$TS_Connector = Get-WmiObject Win32_TerminalServiceSetting -N "root/cimv2/terminalservices" -computername $_ -Authentication PacketPrivacy
$TS_Connector.Logons=0
$TS_Connector.Put()
$TS_Connector.Get()
if ($TS_Connector.Logons -eq 0) {
"OK"
} else {
"Error"
}
}
}#TRY
CATCH {
Write-Warning -Message "$($Error[0].Exception)"
}
}
能够禁用对脱机服务器的访问 RDP的登录模式是存储在注册表中的每个服务器配置。登录模式的配置存储在注册表中的两个不同位置: 排水模式
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Terminal Server\TSServerDrainMode
0 = Allow all connections
1 = Allow reconnections, but prevent new logon until reboot
2 = Allow reconnections, but prevent new logon
登录
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\WinStationsDisabled
0 = Enabled
1 = Disabled
当服务器处于排放模式时,WinStationDisabled始终为0(已启用)