- <#
- .SYNOPSIS
- This script adds a program to the firewall.
- .DESCRIPTION
- This script used the firewall com object to add
- a new application to the firewall.
- .NOTES
- File Name : Add-FirewallApplication.ps1
- Author : Thomas Lee - tfl@psp.co.uk
- Requires : PowerShell Version 2.0
- .LINK
- This script posted to:
- http://pshscripts.blogspot.com/2010/03/add-firewallapplicationps1.html
- MSDN Sample posted at:
- http://msdn.microsoft.com/en-us/library/aa366421%28VS.85%29.aspx
- .EXAMPLE
- At start of script, authorised applications are:
- Name Enabled
- ---- -------
- Delivery Manager Service True
- BitTornado True
- driver True
- driver True
- BitTorrent True
- DNA True
- Microsoft Office OneNote True
- After adding Notepad - here are authorised applications
- Name Enabled
- ---- -------
- Notepad True
- Delivery Manager Service True
- BitTornado True
- driver True
- driver True
- BitTorrent True
- DNA True
- Microsoft Office OneNote True
- #>
- ##
- # Start of script
- ##
- # Set constants
- $NET_FW_PROFILE_DOMAIN = 0
- $NET_FW_PROFILE_STANDARD = 1
- # Scope
- $NET_FW_SCOPE_ALL = 0
- # IP Version - ANY is the only allowable setting for now
- $NET_FW_IP_VERSION_ANY = 2
- # Create the firewall manager object.
- $fwMgr = new-object -com HNetCfg.FwMgr
- # Get the current profile for the local firewall policy.
- $profile = $fwMgr.LocalPolicy.CurrentProfile
- # Display applications available
- "At start of script, authorised applications are:"
- $profile.AuthorizedApplications | ft name, enabled -AutoSize
- # Create application to add to firewall
- $app = New-Object -com HNetCfg.FwAuthorizedApplication
- $app.ProcessImageFileName = "C:\windows\notepad.exe"
- $app.Name = "Notepad"
- $app.Scope = $NET_FW_SCOPE_ALL
- # Use either Scope or RemoteAddresses, but not both
- # $app.RemoteAddresses = "*"
- $app.IpVersion = $NET_FW_IP_VERSION_ANY
- $app.Enabled = $TRUE
- # Use this line if you want to add the app, but disabled.
- # $app.Enabled = FALSE
- $profile.AuthorizedApplications.Add($app)
- # Show applications after addition
- "After adding Notepad - here are authorised applications"
- $profile.AuthorizedApplications | ft name, enabled -AutoSize
- # End of script
This blog contains PowerShell scripts, more PowerShell scripts and still more PowerShell scripts. Occasionally you may see some organisational posts.
Sunday, 21 March 2010
Add-FireWallApplication.ps1
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment