Category filter

Script to block websites on Windows

Website blacklisting is a defense mechanism that prevents users from accessing harmful and unwanted web URLs. The browser prompts a blocked access notification when the users access the blacklisted websites. Depending on the enterprise requirements, those websites that are unnecessary for the users can be blacklisted. While there are various ways of filtering web content, executing custom scripts is one of the easiest methods of performing it remotely.


The Sample Scripts provided below are adapted from third-party Open-Source sites.

PowerShell Script

In this PowerShell script, we create a new outbound firewall rule to block access to specific websites.

For example, to block the URL with IP address,

The site will be blacklisted on all the browsers on the device.


  • If you are unsure about the IP address of a given website, you may even use the ping command. It helps to retrieve the IP address associated with a URL. For example, you want to fetch the IP address for the website, use the following command,

  • The firewall rule applied on the device using the NetFirewallRule command remains associated with the device unless you revoke it. Admin users can restore the default firewall policy on the device by performing a few steps.
    • Open Windows Defender Firewall on the device.
    • Go to Advanced settings.
    • Click on the Restore Default Policy button displayed under Actions.
    • Click Yes to confirm.
  • It is recommended to manually validate the script execution on a system before executing the action in bulk.
  • Hexnode will not be responsible for any damage/loss to the system on the behavior of the script.
  • Sample Script Repository