- <#
- .SYNOPSIS
- This script gets the status of the host firewall
- and ensures the firewall IS running!
- .DESCRIPTION
- This script gets the status and displays it to the
- console. The script also turns on the firewall if it's
- currently off. It's a simpler script than in MSDN for VBScript!
- .NOTES
- File Name : Get-FirewallStatus.ps1
- Author : Thomas Lee - tfl@psp.co.uk
- Requires : PowerShell Version 2.0
- .LINK
- This script posted to:
- http://pshscripts.blogspot.com/2010/03/get-firewallstatusps1.html
- MSDN Sample posted at:
- http://msdn.microsoft.com/en-us/library/aa366442%28VS.85%29.aspx
- .EXAMPLE
- PSH [C:\foo]: .\Get-FirewallStatus.ps1
- Firewall Enabled : True
- Firewall Exceptions Not Allowed: False
- #>
- ##
- # Start Script
- ##
- # Create the firewall manager object.
- $fwMgr = New-Object -com HNetCfg.FwMgr
- # Get the current profile for the local firewall policy.
- $profile = $fwMgr.LocalPolicy.CurrentProfile
- # Verify that the Firewall is enabled. If it isn't, then enable it.
- if (!$profile.FirewallEnabled)
- {$profile.FirewallEnabled = $TRUE}
- # Display details
- "Firewall Enabled : {0}" -f $profile.FirewallEnabled
- "Firewall Exceptions Not Allowed: {0}" -f $profile.ExceptionsNotAllowed
- # End Script
This blog contains PowerShell scripts, more PowerShell scripts and still more PowerShell scripts. Occasionally you may see some organisational posts.
Creating an instance of the COM component with CLSID {304CE942-6E39-40D8-943A-B913C40C9CD4} from the IClassFactory failed due to the following error: 800706d9.
ReplyDeleteAt :line:29 char:19
+ $fwMgr = New-Object <<<< -com HNetCfg.FwMgr
The term 'profile.FirewallEnabled' is not recognized as the name of a cmdlet, function, script file, or operable progra
m. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At C:\Users\administrator.INNERVATION\Desktop\Get-FirewallStatus.ps1:36 char:29
+ {profile.FirewallEnabled <<<< = $TRUE}
+ CategoryInfo : ObjectNotFound: (profile.FirewallEnabled:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
The first error is a problem with DCOM at your end - not sure of the cause. Second error looks like a typo and is now fixed.
ReplyDeletePing me off line if the DCOM issue persists.