If you need to enable RDP on multiple remote servers, you can use PowerShell remoting to execute the commands remotely. This is particularly useful for managing Server Core installations.
First, ensure PowerShell remoting is enabled on the target server:
# Enable PowerShell remoting on the target server (run locally on target)
Enable-PSRemoting -Force
Set-Item WSMan:\localhost\Client\TrustedHosts -Value "*" -Force # For non-domain environments
Then execute the RDP enablement remotely:
# Define target server and credentials
$RemoteComputer = "SERVER-NAME-OR-IP"
$Credential = Get-Credential -Message "Enter credentials for $RemoteComputer"
# Execute RDP enablement on remote server
Invoke-Command -ComputerName $RemoteComputer -Credential $Credential -ScriptBlock {
# Enable RDP
Set-ItemProperty -Path 'HKLM:\System\CurrentControlSet\Control\Terminal Server' -Name 'fDenyTSConnections' -Value 0
# Enable firewall rules
Enable-NetFirewallRule -DisplayGroup "Remote Desktop"
# Enable NLA
Set-ItemProperty -Path 'HKLM:\System\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp' -Name 'UserAuthentication' -Value 1
# Restart Terminal Services
Restart-Service -Name "TermService" -Force
# Return status
$rdpStatus = (Get-ItemProperty "HKLM:\System\CurrentControlSet\Control\Terminal Server").fDenyTSConnections -eq 0
$serviceStatus = (Get-Service -Name "TermService").Status
return @{
ComputerName = $env:COMPUTERNAME
RDPEnabled = $rdpStatus
ServiceStatus = $serviceStatus
Timestamp = Get-Date
}
}
# Verify the remote configuration
Write-Host "Remote RDP configuration completed" -ForegroundColor Green
For multiple servers, you can use a loop:
# Enable RDP on multiple servers
$servers = @("Server1", "Server2", "Server3")
$credential = Get-Credential
foreach ($server in $servers) {
try {
Write-Host "Configuring RDP on $server..." -ForegroundColor Yellow
$result = Invoke-Command -ComputerName $server -Credential $credential -ScriptBlock {
Set-ItemProperty -Path 'HKLM:\System\CurrentControlSet\Control\Terminal Server' -Name 'fDenyTSConnections' -Value 0
Enable-NetFirewallRule -DisplayGroup "Remote Desktop"
Restart-Service -Name "TermService" -Force
return "Success"
}
Write-Host "$server: $result" -ForegroundColor Green
}
catch {
Write-Host "$server: Failed - $($_.Exception.Message)" -ForegroundColor Red
}
}
Verification: Each remote command should return success status. Test RDP connectivity to each server after configuration.
Pro tip: For domain environments, you don't need to modify TrustedHosts. Use domain credentials and the commands will work seamlessly across domain-joined servers.