What It Does
This script changes nothing until you set DryRun=false and Approve=enable-network-isolation. The dry run resolves the host names and lists every rule it would create. It refuses to make more than 25 changes in one run unless you raise MaxChanges, and servers are refused unless IncludeServers is true.
It saves the firewall policy and the current Domain, Private and Public settings, then creates the Windows Firewall rule group MSP Outpost Isolation: one rule allowing outbound traffic to every address in AllowedHosts and one outbound rule for each program in AllowedPrograms. On all three profiles it switches the firewall on, sets the default inbound and outbound actions to Block, and disables inbound allow rules. It switches off other enabled outbound allow rules in the PC's own policy except the DHCP client rules. Loopback traffic is unaffected. It records the disabled rules so the undo can restore them.
To avoid locking yourself out, the RMM agent that started the script is allowed if detected. A live run stops before changing anything if it finds no agent and AllowedPrograms is empty. The first host in AllowedHosts must answer before and after the change. If the first isolation fails, the script attempts to restore the saved settings and reports if rollback also fails. AutoUndoMinutes above 0 registers a one-shot scheduled task that undoes the isolation after that many minutes.
Host names are resolved to addresses when the script runs, so if a service moves, run it again. Include your DNS servers in AllowedHosts. A third-party firewall makes it end SKIPPED, and a domain Group Policy that controls the firewall can override it. Use disable-network-isolation to undo it.
Before You Run It
- Put your RMM, EDR and DNS addresses in AllowedHosts, with one host name or IP address first. It is used for the test connection.
- Add the RMM agent executable to AllowedPrograms if you are not sure the agent is found automatically.
- Run it once as a dry run and read the rules it would create.
- Consider AutoUndoMinutes on a first run, and keep the firewall policy backup available if the undo fails.
Type and Risk
- Type: Action. It makes its change, checks the change worked and says what changed. It exits 0, or 2 when it could not do the job.
- Risk: High. It is a dry run unless you set both DryRun=false and Approve=enable-network-isolation, and it stops before making more than 25 changes in one run unless you raise MaxChanges. Run it once as a dry run and read the list first.
- What it changes: Creates the Windows Firewall rule group MSP Outpost Isolation, blocks all other inbound and outbound traffic on all profiles, switches off other enabled outbound allow rules, saves the old firewall settings, optionally registers a scheduled task that undoes it.
- Restart: It never restarts the machine.
- Typical run: 10 to 60 seconds.
- Example answer: "Isolated: traffic allowed only to 2 address(es) (192.168.1.1) and 1 program(s); 140 other outbound rule(s) disabled; test connection ok (192.168.1.1 via dns)"
- Tested before listing on Windows 11 with Windows PowerShell 5.1, run as SYSTEM, against its own test cases.
Inputs
Pass an input as an argument (-Name value), as an environment variable with the same name, which is how most RMMs pass script variables, or change its default in the param() block at the top of the script. An argument wins over an environment variable, which wins over the default.
- AllowedHosts: Where this PC may still send traffic: host names (FQDNs), IP addresses or CIDR ranges of your RMM, EDR and DNS servers, separated by commas, semicolons or new lines. The FIRST entry must be one host name or IP address (it is used for the test connection). Required.
- AllowedPrograms: Full paths of programs allowed to use the network to any address (for example the RMM agent executables), separated by commas, semicolons or new lines. Each file must exist. Default empty.
- AutoUndoMinutes: 0 (default) = no automatic undo. 1 to 1440 = a scheduled task removes the isolation by itself after that many minutes.
- IncludeServers: true to allow isolating a Windows Server or domain controller. Default false.
Every script also takes DryRun, OutputFormat (Text, Answer, Json or Csv), ExportPath and ResultField, which writes the answer to an RMM custom field.
License
Provided "as is" under the MIT License, without warranty of any kind. Test before production use. MSP Outpost and User First Digital Inc. accept no liability for any damage or loss.