Setup: Computer with PowerShell installed

Problem: You need to check the firewall status from a script, for a local or a remote server.

Solution:

filter global:get-firewallstatus ([string]$computer = $env:computername)
	{
	if ($_) { $computer = $_ }

	$HKLM = 2147483650

	$reg = get-wmiobject -list -namespace root\default -computer $computer | where-object { $_.name -eq "StdRegProv" }
	$firewallEnabled = $reg.GetDwordValue($HKLM, "System\ControlSet001\Services\SharedAccess\Parameters\FirewallPolicy\DomainProfile","EnableFirewall")

	[bool]($firewallEnabled.uValue)
	}

get-firewallstatus [<computername>]

Tip 1: Use Run As to open a PowerShell session with an administrative user
Tip 2: Get status for all computer from AD with

Get-QADComputer | select-object -property @{n='Name';e={$_.name}},@{n='FirewallStatus';e={get-firewallstatus $_.name}} 

Leave a Reply

Your email address will not be published. Required fields are marked *