Created
October 3, 2023 08:29
-
-
Save yerttle/fc3911ef8938f2850a7fe2a81bd2f414 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Registry paths to check | |
$registryPaths = @( | |
"HKLM:\SYSTEM\CurrentControlSet\Services\SharedAccess\Parameters\FirewallPolicy\PublicProfile", | |
"HKLM:\SYSTEM\CurrentControlSet\Services\SharedAccess\Parameters\FirewallPolicy\DomainProfile", | |
"HKLM:\SYSTEM\CurrentControlSet\Services\SharedAccess\Parameters\FirewallPolicy\StandardProfile" | |
) | |
# Loop through each path and get the EnableFirewall value | |
foreach ($path in $registryPaths) { | |
try { | |
# Attempt to read the EnableFirewall value | |
$enableFirewall = Get-ItemProperty -Path $path -Name "EnableFirewall" -ErrorAction Stop | |
$isFirewallEnabled = [bool]$enableFirewall.EnableFirewall | |
Write-Host "EnableFirewall is $($isFirewallEnabled) for path '$path'" | |
} catch { | |
# Error handling: output a message if the value could not be read | |
Write-Host "Failed to read EnableFirewall value at '$path': $($_.Exception.Message)" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment