PowerShell
Copyright (C) Microsoft Corporation. All rights reserved.
# display current Remote Desktop setting
# 0 = allow Remote Desktop
# 1 = disallow Remote Desktop
PS C:\Users\Administrator> Get-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Control\Terminal Server" -Name "fDenyTSConnections"
fDenyTSConnections : 1
PSPath : Microsoft.PowerShell.Core\Registry::HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSe
t\Control\Terminal Server
PSParentPath : Microsoft.PowerShell.Core\Registry::HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSe
t\Control
PSChildName : Terminal Server
PSDrive : HKLM
PSProvider : Microsoft.PowerShell.Core\Registry
# display current Remote Desktop connection setting
# 0 = allow all
# 1 = allow connections only from computers running Remote Desktop with Network Level Authentication (recommended)
PS C:\Users\Administrator> Get-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp" -Name "UserAuthentication"
UserAuthentication : 1
PSPath : Microsoft.PowerShell.Core\Registry::HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSe
t\Control\Terminal Server\WinStations\RDP-Tcp
PSParentPath : Microsoft.PowerShell.Core\Registry::HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSe
t\Control\Terminal Server\WinStations
PSChildName : RDP-Tcp
PSDrive : HKLM
PSProvider : Microsoft.PowerShell.Core\Registry
# set to allow Remote Desktop
PS C:\Users\Administrator> Set-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Control\Terminal Server" -Name "fDenyTSConnections" -Value "0"
# set to allow connections only from computers running Remote Desktop with Network Level Authentication
PS C:\Users\Administrator> Set-ItemProperty -Path 'HKLM:\SYSTEM\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp' -Name "UserAuthentication" -Value "1"
# on command configuration, it needs to configure Windows Firewall manually
# rules for Remote Desktop are already set by default, so it needs to enable them manually
PS C:\Users\Administrator> Get-NetFirewallRule | Where-Object Name -like 'RemoteDesktop*' | Out-String -Stream | Select-String "^Name","Enabled"
Name : RemoteDesktop-In-TCP-WS
Enabled : False
Name : RemoteDesktop-In-TCP-WSS
Enabled : False
Name : RemoteDesktop-Shadow-In-TCP
Enabled : False
Name : RemoteDesktop-UserMode-In-TCP
Enabled : False
Name : RemoteDesktop-UserMode-In-UDP
Enabled : False
# enable it
PS C:\Users\Administrator> Set-NetFirewallRule -Name "RemoteDesktop-In-TCP-WS" -Enabled True
# enable them all
PS C:\Users\Administrator> Get-NetFirewallRule | Where-Object Name -like 'RemoteDesktop*' | Set-NetFirewallRule -Enabled True
|