Enable-WindowsFirewallService

  • 14 April 2018
  • Sean Huggans
Description: 

Script can be used in application package/adjustments/shimming scripts to ensure the windows firewall service is on

Language: 
Powershell
Usage Type: 
Packaging Function
Script Source: 
# To Ensure the firewall service is on, add the below function and call it adding any firewall rules
function Enable-WindowsFirewallService {
########################################
# Enable Windows Firewall Service
# 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 -Message "Making Sure Windows Firewall is enabled and setting default behaviors..."
    $ServiceName = $(Get-WmiObject -Class Win32_Service -Property * | where-object {(($_.DisplayName -like "*Windows*") -and ($_.DisplayName -like "*Firewall*"))}).DisplayName
    try
    {
        $Service = Get-WmiObject -Class Win32_Service -filter "displayname='$ServiceName'" -ErrorAction stop
        $Service.ChangeStartMode("Automatic") | Out-Null
        if ($Service.State -ne "Running")
        {
            $Service.StartService() | Out-Null
        }
        Log-Action -Message " - Changed the Startup Type of the '$ServiceName' service to 'Automatic'."
        return $true
    } catch {
        Log-Action -Message " - Error changing the Startup Type of the '$ServiceName' service to 'Automatic'!  You will need to do this manually!"
        return $false
    }
}
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.