PSScripts/Monitor-WindowsFirewallState.ps1

23 lines
697 B
PowerShell
Raw Permalink Normal View History

2023-12-18 18:01:52 +00:00
# Monitors the state of windows firewall
function Write-Diag {
foreach ($Message in $Messages) { $Message }
}
$FirewallState = @()
$FirewallProfiles = Get-NetFirewallProfile | Where-Object {$_.Enabled -eq $false}
If($FirewallProfiles){$FirewallState += "$($FirewallProfiles.name) Profile is disabled"}
$FirewallAllowed = Get-NetFirewallProfile | Where-Object {$_.DefaultInboundAction -eq "Allow"}
If($FirewallAllowed){$FirewallState += "$($FirewallAllowed.name) Profile is set to $($FirewallAllowed.DefaultInboundAction) inbound traffic"}
if(!$FirewallState){Write-Host "healthy"}
else {
Write-Host $FirewallState
Write-Diag @($FirewallProfiles,$FirewallAllowed)
exit 1
}