Thursday 18 March 2010

Enable-ICMP.ps1

  1. <# 
  2. .SYNOPSIS 
  3.     This script Enables ICMP on the Standard Firewall profile. 
  4. .DESCRIPTION 
  5.     This script creates a Firewall object then configures it. 
  6. .NOTES 
  7.     File Name  : Enable-ICMP.ps1 
  8.     Author     : Thomas Lee - tfl@psp.co.uk 
  9.     Requires   : PowerShell Version 2.0 
  10. .LINK 
  11.     This script posted to: 
  12.         http://www.pshscripts.blogspot.com 
  13.     MSDN Sample posted at: 
  14.         http:// 
  15. .EXAMPLE 
  16.     PSH [C:\foo]: . 'E:\PowerShellScriptLib\COM\HNetCfg.FwMgr\Enable-ICMP.ps1' 
  17.  
  18.     AllowOutboundDestinationUnreachable : False 
  19.     AllowRedirect                       : False 
  20.     AllowInboundEchoRequest             : False 
  21.     AllowOutboundTimeExceeded           : False 
  22.     AllowOutboundParameterProblem       : False 
  23.     AllowOutboundSourceQuench           : False 
  24.     AllowInboundRouterRequest           : False 
  25.     AllowInboundTimestampRequest        : False 
  26.     AllowInboundMaskRequest             : False 
  27.     AllowOutboundPacketTooBig           : True 
  28.  
  29.     After Script ran: 
  30.     AllowOutboundDestinationUnreachable : False 
  31.     AllowRedirect                       : False 
  32.     AllowInboundEchoRequest             : True 
  33.     AllowOutboundTimeExceeded           : False 
  34.     AllowOutboundParameterProblem       : False 
  35.     AllowOutboundSourceQuench           : False 
  36.     AllowInboundRouterRequest           : False 
  37.     AllowInboundTimestampRequest        : False 
  38.     AllowInboundMaskRequest             : False 
  39.     AllowOutboundPacketTooBig           : True 
  40. #> 
  41.  
  42. ## 
  43. # Start of script 
  44. ## 
  45.  
  46. # Set strict mode 
  47. Set-StrictMode -Version 2.0 
  48.  
  49. # Set Constants 
  50. $NET_FW_PROFILE_DOMAIN   = 0 
  51. $NET_FW_PROFILE_STANDARD = 1 
  52.  
  53. # Create the firewall manager object. 
  54. $fwMgr = New-Object -com HNetCfg.FwMgr 
  55.  
  56. # Get the current profile for the local firewall policy. 
  57. $profile = $fwMgr.LocalPolicy.GetProfileByType($NET_FW_PROFILE_STANDARD
  58.  
  59. # Display current ICMP settings 
  60. $Profile.IcmpSettings 
  61.  
  62. # Now set it to True 
  63. $profile.IcmpSettings.AllowInboundEchoRequest = $True 
  64.  
  65. # Use this line if you want to disable the setting. 
  66. #profile.IcmpSettings.AllowInboundEchoRequest = $FALSE 
  67.  
  68. # Display it again 
  69. "After Script ran: " 
  70. $Profile.IcmpSettings 
  71.  
  72. # End Script 

No comments: