Skip to content

Instantly share code, notes, and snippets.

@yerttle
Created October 3, 2023 08:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yerttle/fc3911ef8938f2850a7fe2a81bd2f414 to your computer and use it in GitHub Desktop.
Save yerttle/fc3911ef8938f2850a7fe2a81bd2f414 to your computer and use it in GitHub Desktop.
# 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