5 Replies Latest reply on Dec 18, 2012 6:22 PM by Joshua Baker

    Powershell commands freezing console while browsing

      I am trying to pull a table of all the active firewall rules on a Windows 2008 server.  I am using the following command remote executed command in an extended object:

       

      $FwProtocols=@{1='ICMPv4';2='IGMP';6='TCP';17='UDP';41='IPv6';43='IPv6Route'; 44='IPv6Frag'; 47='GRE'; 58='ICMPv6';59='IPv6NoNxt';60='IPv6Opts';112='VRRP'; 113='PGM';115='L2TP'; 'ICMPv4'=1;'IGMP'=2;'TCP'=6;'UDP'=17;'IPv6'=41;'IPv6Route'=43;'IPv6Frag'=44;'GRE'=47; 'ICMPv6'=48;'IPv6NoNxt'=59;'IPv6Opts'=60;'VRRP'=112; 'PGM'=113;'L2TP'=115};(New-Object -comObject HNetCfg.FwPolicy2).rules | where-object {$_.Profiles -bAND 1 -and $_.Enabled} | select @{Name='Rule';expression={$_.name.replace(' ','') + '-' + $FwProtocols[$_.protocol] +'='}},@{Name='Enabled';expression={$_.Enabled}} | Format-Table -auto -HideTableHeaders
      

       

      I have successfully run the command via the NSH console as long as I escape all of the dollar signs:

       

      \$FwProtocols=@{1='ICMPv4';2='IGMP';6='TCP';17='UDP';41='IPv6';43='IPv6Route'; 44='IPv6Frag'; 47='GRE'; 58='ICMPv6';59='IPv6NoNxt';60='IPv6Opts';112='VRRP'; 113='PGM';115='L2TP'; 'ICMPv4'=1;'IGMP'=2;'TCP'=6;'UDP'=17;'IPv6'=41;'IPv6Route'=43;'IPv6Frag'=44;'GRE'=47; 'ICMPv6'=48;'IPv6NoNxt'=59;'IPv6Opts'=60;'VRRP'=112; 'PGM'=113;'L2TP'=115};(New-Object -comObject HNetCfg.FwPolicy2).rules | where-object {\$_.Profiles -bAND 1 -and \$_.Enabled} | select @{Name='Rule';expression={\$_.name.replace(' ','') + '-' + \$FwProtocols[\$_.protocol] +'='}},@{Name='Enabled';expression={\$_.Enabled}} | Format-Table -auto -HideTableHeaders
      

       

      Here is the expected output:

       

      TrendMicroOfficeScanListener-TCP=                                              True
      MicrosoftOfficeCommunicator2007-UDP=                                           True
      MicrosoftOfficeCommunicator2007-TCP=                                           True
      WebKit-=                                                                       True
      RemoteDesktop(TCP-In)-TCP=                                                     True
      CoreNetworking-DestinationUnreachable(ICMPv6-In)-ICMPv6=                       True
      CoreNetworking-PacketTooBig(ICMPv6-In)-ICMPv6=                                 True
      CoreNetworking-PacketTooBig(ICMPv6-Out)-ICMPv6=                                True
      CoreNetworking-TimeExceeded(ICMPv6-In)-ICMPv6=                                 True
      CoreNetworking-TimeExceeded(ICMPv6-Out)-ICMPv6=                                True
      CoreNetworking-ParameterProblem(ICMPv6-In)-ICMPv6=                             True
      CoreNetworking-ParameterProblem(ICMPv6-Out)-ICMPv6=                            True
      CoreNetworking-NeighborDiscoverySolicitation(ICMPv6-In)-ICMPv6=                True
      CoreNetworking-NeighborDiscoverySolicitation(ICMPv6-Out)-ICMPv6=               True
      CoreNetworking-NeighborDiscoveryAdvertisement(ICMPv6-In)-ICMPv6=               True
      CoreNetworking-NeighborDiscoveryAdvertisement(ICMPv6-Out)-ICMPv6=              True
      CoreNetworking-RouterAdvertisement(ICMPv6-In)-ICMPv6=                          True
      CoreNetworking-RouterAdvertisement(ICMPv6-Out)-ICMPv6=                         True
      CoreNetworking-RouterSolicitation(ICMPv6-In)-ICMPv6=                           True
      CoreNetworking-RouterSolicitation(ICMPv6-Out)-ICMPv6=                          True
      CoreNetworking-MulticastListenerQuery(ICMPv6-In)-ICMPv6=                       True
      CoreNetworking-MulticastListenerQuery(ICMPv6-Out)-ICMPv6=                      True
      CoreNetworking-MulticastListenerReport(ICMPv6-In)-ICMPv6=                      True
      CoreNetworking-MulticastListenerReport(ICMPv6-Out)-ICMPv6=                     True
      CoreNetworking-MulticastListenerReportv2(ICMPv6-In)-ICMPv6=                    True
      CoreNetworking-MulticastListenerReportv2(ICMPv6-Out)-ICMPv6=                   True
      CoreNetworking-MulticastListenerDone(ICMPv6-In)-ICMPv6=                        True
      CoreNetworking-MulticastListenerDone(ICMPv6-Out)-ICMPv6=                       True
      CoreNetworking-DestinationUnreachableFragmentationNeeded(ICMPv4-In)-ICMPv4=    True
      CoreNetworking-InternetGroupManagementProtocol(IGMP-In)-IGMP=                  True
      CoreNetworking-InternetGroupManagementProtocol(IGMP-Out)-IGMP=                 True
      CoreNetworking-DynamicHostConfigurationProtocol(DHCP-In)-UDP=                  True
      CoreNetworking-DynamicHostConfigurationProtocol(DHCP-Out)-UDP=                 True
      CoreNetworking-DynamicHostConfigurationProtocolforIPv6(DHCPV6-In)-UDP=         True
      CoreNetworking-DynamicHostConfigurationProtocolforIPv6(DHCPV6-Out)-UDP=        True
      CoreNetworking-Teredo(UDP-In)-UDP=                                             True
      CoreNetworking-Teredo(UDP-Out)-UDP=                                            True
      CoreNetworking-IPHTTPS(TCP-In)-TCP=                                            True
      CoreNetworking-IPHTTPS(TCP-Out)-TCP=                                           True
      CoreNetworking-IPv6(IPv6-In)-IPv6=                                             True
      CoreNetworking-IPv6(IPv6-Out)-IPv6=                                            True
      CoreNetworking-GroupPolicy(NP-Out)-TCP=                                        True
      CoreNetworking-GroupPolicy(TCP-Out)-TCP=                                       True
      CoreNetworking-DNS(UDP-Out)-UDP=                                               True
      CoreNetworking-GroupPolicy(LSASS-Out)-TCP=                                     True
      RemoteAssistance(RAServerTCP-In)-TCP=                                          True
      RemoteAssistance(RAServerTCP-Out)-TCP=                                         True
      RemoteAssistance(DCOM-In)-TCP=                                                 True
      RemoteAssistance(TCP-In)-TCP=                                                  True
      RemoteAssistance(TCP-Out)-TCP=                                                 True
      RemoteAssistance(SSDPUDP-In)-UDP=                                              True
      RemoteAssistance(SSDPUDP-Out)-UDP=                                             True
      RemoteAssistance(SSDPTCP-In)-TCP=                                              True
      RemoteAssistance(SSDPTCP-Out)-TCP=                                             True
      RemoteAssistance(PNRP-In)-UDP=                                                 True
      RemoteAssistance(PNRP-Out)-UDP=                                                True
      
      

       

      Any time I attempt to browse the component for this extended object, it freezes the entire console.