Category filter

Script to configure Firewall on Windows devices

Windows Firewall is a security mechanism that protects the device from unauthorized access. It helps secure the endpoints and permits you to create network rules for regulating network traffic. This doc assists you on how to configure firewall settings and rules using scripts via Hexnode UEM.

Disclaimer:

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

Setting up Windows Firewall using scripts

You can use both the Batch files and PowerShell commands to enable the firewall on Windows devices from the Hexnode console.

1. Batch Script

  • To enable Firewall on all profiles specifically domain, private and public:
  • To disable Firewall on all profiles specifically domain, private and public:
  • To enable Firewall on current profile:

    Replace ‘currentprofile’ with ‘domainprofile’, ‘publicprofile’, or ‘privateprofile’ to set the Firewall state for a particular profile.

  • To disable Firewall on current profile:

    Replace ‘currentprofile’ with ‘domainprofile’, ‘publicprofile’, or ‘privateprofile’ to set the Firewall state for a particular profile.

  • To add a Firewall rule name for any given application (for instance, Google Chrome) meant for the inbound traffic to the device:

  • To allow a port for inbound traffic in Firewall:

  • To block a port for inbound traffic in Firewall:

  • To remove a configured Firewall rule:

    Replace new_rule with the name of the configured Firewall rule.

2. PowerShell Script

  • To enable Firewall on all profiles specifically domain, private and public:

    Replace ‘All’ with ‘Domain,’ ‘Private,’ or ‘Public’ to enable Firewall across respective profiles.

  • To disable Firewall on all profiles specifically domain, private and public:

    Replace ‘All’ with ‘Domain,’ ‘Private,’ or ‘Public’ to enable Firewall across respective profiles.

  • To add Firewall rule name for any given application (for instance, Google Chrome) meant for the inbound traffic to the device:

  • To allow a port for outbound traffic in Firewall:

  • To block a port for outbound traffic in Firewall:

  • To remove a configured Firewall rule:

    Replace new_rule with the name of the configured Firewall rule.

Notes:

  • 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