Skip to content

Instantly share code, notes, and snippets.

@jbfriedrich
Created July 31, 2014 21:11
Show Gist options
  • Save jbfriedrich/dfd85370ad15fd510265 to your computer and use it in GitHub Desktop.
Save jbfriedrich/dfd85370ad15fd510265 to your computer and use it in GitHub Desktop.
Only allow RDP from whitelisted IPs
# Set execution policy
# AllSigned : Every script must bear a valid signature
# RemoteSigned : Must be signed by a trusted publisher (for example Microsoft)
# Unrestricted : No restrictions whatsoever, every script can run
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned
# Whitelisted IPs which are allowed to use the services on this host
$whitelistIPs = "8.8.8.8", "127.0.0.1"
# DisplayNames for the firewall rules for Remote Desktop
$remoteDeskopFwRules = "Remote Desktop - User Mode (TCP-In)", "Remote Desktop - User Mode (UDP-In)"
foreach ($rule in $remoteDeskopFwRules) {
# This will only configure and enable the Firewall ports. The service needs to be (re-)started separately!
Set-NetFireWallRule -DisplayName $rule -Enabled True -Direction Inbound -RemoteAddress $whitelistIPs
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment