Set-WindowsFirewallActive

  • 14 April 2018
  • Sean Huggans
Description: 

Function can be used in application package/adjustments/shimming scripts to ensure the Windows Firewall is active

Language: 
Powershell
Usage Type: 
Packaging Function
Script Source: 
# To Ensure the firewall is active
function Set-WindowsFirewallActive {
########################################
# Set Firewall to Active State
# Function Date: 18.4.14.1
# Function By: Sean Huggans
########################################
# Usage Note 1: function is dependent on the below 2 lines being present at the beginning of your script, as well as the standard logging function being present
    $script:wmiOS = Get-WmiObject -Class Win32_OperatingSystem;
    $script:OS = $wmiOS.Caption
    Log-Action ""
    try {
        if ($OS -like "*Windows 10*") {
            Set-NetFirewallProfile -Profile Domain,Public,Private -Enabled True -Confirm:$false
            Set-NetFirewallProfile -name Private -DefaultInboundAction Block -Confirm:$false
            Set-NetFirewallProfile -name Public -DefaultInboundAction Block -Confirm:$false
            Set-NetFirewallProfile -name Domain -DefaultInboundAction Block -Confirm:$false
        } else {
            & netsh advfirewall set privateprofile firewallpolicy blockinbound,allowoutbound | Out-Null
            & netsh advfirewall set publicprofile firewallpolicy blockinbound,allowoutbound | Out-Null
            & netsh advfirewall set domainprofile firewallpolicy blockinbound,allowoutbound | Out-Null
        }
        Log-Action -Message " - Set default profile behaviors.  Default Inbound Action for all profiles is set to Block (default)."
    } catch {
        Log-Action -Message " - Error setting default profile behaviors.  You will need to set Inbound Action for all profiles to Block (default)!"
    }
}
Note: that all applications posted here are posted for use, both commercial and non-commercial, free of charge, and as such are provided as-is, without warranty of any kind whatsoever. visuaFUSION, FMSCUG or any other program listed here's author are not responsible for any damages or shortcomings that result from usage of any of these applications.
Error | visuaFUSION Systems Solutions Blog

Error message

  • Warning: Cannot modify header information - headers already sent by (output started at /mnt/home/visuafus/public_html/bahusa.net/includes/common.inc:2861) in drupal_send_headers() (line 1551 of /mnt/home/visuafus/public_html/bahusa.net/includes/bootstrap.inc).
  • Error: Call to undefined function mail() in DefaultMailSystem->mail() (line 79 of /mnt/home/visuafus/public_html/bahusa.net/modules/system/system.mail.inc).

Error

The website encountered an unexpected error. Please try again later.