I think there's a problem with this if statement.
Function Get-IsFirewallProfileEnabled([string]$profile)
{
Return [bool](Get-NetFirewallProfile -name "Domain" | Where Enabled -eq "False")
}
# If the firewall for some of the 3 profiles is not enabled
if ( ((Get-IsFirewallProfileEnabled("Domain")) -or (Get-IsFirewallProfileEnabled("Private")) -or (Get-IsFirewallProfileEnabled("Public"))) -eq "False")
{
Write-Output "Enabling..."
# Enable Windows firewall for for all (the 3 profiles)
Set-NetFirewallProfile -Profile Domain,Private,Public -Enabled True
}
Whether I have activated a firewall or not, this script always does nothing. What's happening?
SOLUTION
# Now this function is dynamic
Function Get-IsFirewallProfileEnabled([string]$profile)
{
Return [bool](Get-NetFirewallProfile -name $profile | Where Enabled -eq "True")
}
# If the firewall for some of the 3 profiles is not enabled
if ( -not(Get-IsFirewallProfileEnabled("Domain")) -or -not(Get-IsFirewallProfileEnabled("Private")) -or -not(Get-IsFirewallProfileEnabled("Public")) )
{
Write-Output "Enabling..."
# Enable Windows firewall for for all (the 3 profiles)
Set-NetFirewallProfile -Profile Domain,Private,Public -Enabled True
}