Problem
You want to enable or disable the Windows Firewall.
Solution
To manage the Windows Firewall, use the LocalPolicy.CurrentProfile. FirewallEnabled property of the HNetCfg.FwMgr COM object:
PS >$firewall = NewObject com HNetCfg.FwMgr PS >$firewall.LocalPolicy.CurrentProfile.FirewallEnabled = $true PS >$firewall.LocalPolicy.CurrentProfile.FirewallEnabled True
Discussion
The HNetCfg.FwMgr COM object provides programmatic access to the Windows Firewall in Windows XP SP2 and later. The LocalPolicy.CurrentProfile property provides the majority of its functionality.
For more information about managing the Windows Firewall through its COM API, visit http://msdn.microsoft.com and search for “Using Windows Firewall API.” The documentation provides examples in VBScript but gives a useful overview of the functionality available.
If you are unfamiliar with the VBScriptspecific portions of the documentation, the Microsoft Script Center provides a useful guide to help you convert from VBScript to PowerShell. You can find that document at: http://www.microsoft.com/technet/ scriptcenter/topics/winpsh/convert/default.mspx.