Enable-WindowsFirewallService
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.