← script library
Enable RDP Network Level Authentication with PowerShell
Security & AuditingAugust 17, 2026
Requires NLA so an unauthenticated connection never reaches the logon screen, and sets the RDP security layer to TLS at the same time. The setting is written even on hosts where RDP is currently disabled, so it is already correct if somebody enables it later. Existing sessions are unaffected.
powershell
# Enforce Network Level Authentication for RDP
# Single use case: require NLA so unauthenticated sessions never reach logon UI
#-----------------------------------------------------------------
function Write-Log {
param($Message)
Write-Host "<WRITE-LOG = `"*$Message*`">"
}
$tsPath = "HKLM:\SYSTEM\CurrentControlSet\Control\Terminal Server"
$rdpPath = "$tsPath\WinStations\RDP-Tcp"
$rdpEnabled = (Get-ItemProperty $tsPath -Name fDenyTSConnections -ErrorAction SilentlyContinue).fDenyTSConnections -eq 0
Write-Log "RDP enabled on this host: $rdpEnabled"
if (-not $rdpEnabled) {
Write-Log "RDP is disabled - NLA setting written anyway for when it gets enabled."
}
$current = (Get-ItemProperty $rdpPath -Name UserAuthentication -ErrorAction SilentlyContinue).UserAuthentication
if ($current -eq 1) {
Write-Log "NLA is already enforced - nothing to do."
return
}
Set-ItemProperty -Path $rdpPath -Name "UserAuthentication" -Value 1 -Type DWord
# Also require TLS security layer for the RDP transport
Set-ItemProperty -Path $rdpPath -Name "SecurityLayer" -Value 2 -Type DWord
$verify = (Get-ItemProperty $rdpPath -Name UserAuthentication).UserAuthentication
if ($verify -eq 1) {
Write-Log "NLA enforced (UserAuthentication=1, SecurityLayer=TLS)."
Write-Log "Existing sessions are not affected; new connections must support NLA (all supported Windows versions do)."
} else {
Write-Log "WARNING: failed to write the NLA setting!"
}Run it across your fleet
This script runs as-is on a single host. Paste it into ServerEngine to schedule it, run it on a whole server group in parallel, and keep the credentials out of the file — see the scripts documentation and the credential store.
More in Security & Auditing
Enable the Windows Firewall with PowerShell
2026-08-17Check Windows Firewall Status with PowerShell
2026-08-17Disable SMBv1 with PowerShell
2026-08-17Enforce TLS 1.2 in the Registry with PowerShell
2026-08-17Audit the Local Administrators Group with PowerShell
2026-08-17Audit Failed Logons (Event 4625) with PowerShell
2026-08-17Ready when you are.
Try ServerEngine free for 7 days.