<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>windows firewall rules &#8211; Carl Webster</title>
	<atom:link href="https://www.carlwebster.com/tag/windows-firewall-rules/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.carlwebster.com</link>
	<description>The Accidental Citrix Admin - The site for those who find themselves supporting Citrix involuntarily or accidentally</description>
	<lastBuildDate>Sat, 29 May 2021 15:30:47 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.8.2</generator>
<site xmlns="com-wordpress:feed-additions:1">42228915</site>	<item>
		<title>Listing Windows Firewall Rules Using Microsoft PowerShell</title>
		<link>https://www.carlwebster.com/listing-windows-firewall-rules-using-microsoft-powershell/</link>
					<comments>https://www.carlwebster.com/listing-windows-firewall-rules-using-microsoft-powershell/#comments</comments>
		
		<dc:creator><![CDATA[Carl Webster]]></dc:creator>
		<pubDate>Fri, 16 Nov 2012 11:00:38 +0000</pubDate>
				<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[powershell]]></category>
		<category><![CDATA[windows firewall rules]]></category>
		<guid isPermaLink="false">https://www.carlwebster.com/?p=5010</guid>

					<description><![CDATA[At a customer site recently, I needed a way to list all the Enabled Windows Firewall Inbound Rules.  I could not get what I needed by using the Windows command&#8230;]]></description>
										<content:encoded><![CDATA[<p>At a customer site recently, I needed a way to list all the Enabled Windows Firewall Inbound Rules.  I could not get what I needed by using the Windows</p>
<pre class="brush: bash; title: ; notranslate">netsh advfirewall monitor show firewall rule name=all dir=in</pre>
<p>command so I turned to using PowerShell.</p>
<p>I found the following article by James O’Neill that helped me get started.</p>
<p><a href="http://blogs.technet.com/b/jamesone/archive/2009/02/18/how-to-manage-the-windows-firewall-settings-with-powershell.aspx" target="_blank" rel="noopener">http://blogs.technet.com/b/jamesone/archive/2009/02/18/how-to-manage-the-windows-firewall-settings-with-powershell.aspx</a></p>
<p>What I needed for a headstart was the following code from James&#8217; article:</p>
<pre class="brush: powershell; title: ; notranslate">
Function Get-FireWallRule
{Param ($Name, $Direction, $Enabled, $Protocol, $profile, $action, $grouping)
$Rules=(New-object –comObject HNetCfg.FwPolicy2).rules
If ($name)      {$rules= $rules | where-object {$_.name     -like $name}}
If ($direction) {$rules= $rules | where-object {$_.direction  -eq $direction}}
If ($Enabled)   {$rules= $rules | where-object {$_.Enabled    -eq $Enabled}}
If ($protocol)  {$rules= $rules | where-object {$_.protocol   -eq $protocol}}
If ($profile)   {$rules= $rules | where-object {$_.Profiles -bAND $profile}}
If ($Action)    {$rules= $rules | where-object {$_.Action     -eq $Action}}
If ($Grouping)  {$rules= $rules | where-object {$_.Grouping -like $Grouping}}
$rules}

Get-firewallRule -enabled $true | sort direction,applicationName,name |
format-table -wrap -autosize -property Name, @{Label=”Action”; expression={$Fwaction&#x5B;$_.action]}},
@{label=&quot;Direction&quot;;expression={ $fwdirection&#x5B;$_.direction]}},
@{Label=&quot;Protocol&quot;; expression={$FwProtocols&#x5B;$_.protocol]}} , localPorts,applicationname
</pre>
<p>I created a script named listfw.ps1 and when I ran the script, I received the output shown in Figure 1.</p>
<figure id="attachment_32378" aria-describedby="caption-attachment-32378" style="width: 988px" class="wp-caption alignnone"><a href="https://www.carlwebster.com/wp-content/uploads/2012/11/Figure001.png" target="_blank" rel="noopener"><img fetchpriority="high" decoding="async" class="wp-image-32378 size-full" src="https://www.carlwebster.com/wp-content/uploads/2012/11/Figure001.png" alt="Figure 1" width="988" height="631" srcset="https://www.carlwebster.com/wp-content/uploads/2012/11/Figure001.png 988w, https://www.carlwebster.com/wp-content/uploads/2012/11/Figure001-470x300.png 470w, https://www.carlwebster.com/wp-content/uploads/2012/11/Figure001-900x575.png 900w, https://www.carlwebster.com/wp-content/uploads/2012/11/Figure001-768x490.png 768w, https://www.carlwebster.com/wp-content/uploads/2012/11/Figure001-600x383.png 600w" sizes="(max-width: 988px) 100vw, 988px" /></a><figcaption id="caption-attachment-32378" class="wp-caption-text">Figure 1</figcaption></figure>
<p>The last column wasn’t formatted properly for me so I thought maybe the “–wrap” parameter of  Format-Table was causing the issue.  So I removed the “-wrap” and reran the script.  I received the output shown in Figure 2.</p>
<figure id="attachment_32379" aria-describedby="caption-attachment-32379" style="width: 988px" class="wp-caption alignnone"><a href="https://www.carlwebster.com/wp-content/uploads/2012/11/Figure002.png"><img decoding="async" class="size-full wp-image-32379" src="https://www.carlwebster.com/wp-content/uploads/2012/11/Figure002.png" alt="Figure 2" width="988" height="631" srcset="https://www.carlwebster.com/wp-content/uploads/2012/11/Figure002.png 988w, https://www.carlwebster.com/wp-content/uploads/2012/11/Figure002-470x300.png 470w, https://www.carlwebster.com/wp-content/uploads/2012/11/Figure002-900x575.png 900w, https://www.carlwebster.com/wp-content/uploads/2012/11/Figure002-768x490.png 768w, https://www.carlwebster.com/wp-content/uploads/2012/11/Figure002-600x383.png 600w" sizes="(max-width: 988px) 100vw, 988px" /></a><figcaption id="caption-attachment-32379" class="wp-caption-text">Figure 2</figcaption></figure>
<p>OK, still not what I need.  So I thought maybe the “-autosize” was the culprit.  I removed the “-autosize” and reran the script.  I received the output shown in Figure 3.</p>
<figure id="attachment_32380" aria-describedby="caption-attachment-32380" style="width: 988px" class="wp-caption alignnone"><a href="https://www.carlwebster.com/wp-content/uploads/2012/11/Figure003.png" target="_blank" rel="noopener"><img decoding="async" class="wp-image-32380 size-full" src="https://www.carlwebster.com/wp-content/uploads/2012/11/Figure003.png" alt="Figure 3" width="988" height="631" srcset="https://www.carlwebster.com/wp-content/uploads/2012/11/Figure003.png 988w, https://www.carlwebster.com/wp-content/uploads/2012/11/Figure003-470x300.png 470w, https://www.carlwebster.com/wp-content/uploads/2012/11/Figure003-900x575.png 900w, https://www.carlwebster.com/wp-content/uploads/2012/11/Figure003-768x490.png 768w, https://www.carlwebster.com/wp-content/uploads/2012/11/Figure003-600x383.png 600w" sizes="(max-width: 988px) 100vw, 988px" /></a><figcaption id="caption-attachment-32380" class="wp-caption-text">Figure 3</figcaption></figure>
<p>OK, I am getting further away from what I really.  What I want is a way for the Name column and the ApplicationName column to be full width.</p>
<p>Using get-help format-table –full gave me a clue.  The “-property” parameter has some options available:</p>
<pre class="brush: plain; title: ; notranslate">
-- Name (or Label) &lt;string&gt;
-- Expression &lt;string&gt; or &lt;script block&gt;
-- FormatString &lt;string&gt;
-- Width &lt;int32&gt;
-- Alignment  (value can be &quot;Left&quot;, &quot;Center&quot;, or &quot;Right&quot;)
</pre>
<p>I can see in Jame’s original code he is using the “Label” and “Expression” options.  I just need to figure out how to use the “Width” option.  After much trial and error, I came up with the following code:</p>
<pre class="brush: powershell; title: ; notranslate">
$spaces1 = &quot; &quot; * 71
$spaces2 = &quot; &quot; * 64
Get-firewallRule -enabled $true | sort name | `
format-table -property `
@{label=&quot;Name&quot; + $spaces1             ; expression={$_.name}                    ; width=75}, `
@{label=&quot;Action&quot;                      ; expression={$Fwaction&#x5B;$_.action]}       ; width=6 }, `
@{label=&quot;Direction&quot;                   ; expression={$fwdirection&#x5B;$_.direction]} ; width=9 }, `
@{label=&quot;Protocol&quot;                    ; expression={$FwProtocols&#x5B;$_.protocol]}  ; width=8 }, `
@{label=&quot;Local Ports&quot;                 ; expression={$_.localPorts}              ; width=11}, `
@{label=&quot;Application Name&quot; + $spaces2 ; expression={$_.applicationname}         ; width=80}
</pre>
<p>Running the script gives me the output shown in Figure 4.</p>
<figure id="attachment_32381" aria-describedby="caption-attachment-32381" style="width: 988px" class="wp-caption alignnone"><a href="https://www.carlwebster.com/wp-content/uploads/2012/11/Figure004.png" target="_blank" rel="noopener"><img loading="lazy" decoding="async" class="wp-image-32381 size-full" src="https://www.carlwebster.com/wp-content/uploads/2012/11/Figure004.png" alt="Figure 4" width="988" height="631" srcset="https://www.carlwebster.com/wp-content/uploads/2012/11/Figure004.png 988w, https://www.carlwebster.com/wp-content/uploads/2012/11/Figure004-470x300.png 470w, https://www.carlwebster.com/wp-content/uploads/2012/11/Figure004-900x575.png 900w, https://www.carlwebster.com/wp-content/uploads/2012/11/Figure004-768x490.png 768w, https://www.carlwebster.com/wp-content/uploads/2012/11/Figure004-600x383.png 600w" sizes="auto, (max-width: 988px) 100vw, 988px" /></a><figcaption id="caption-attachment-32381" class="wp-caption-text">Figure 4</figcaption></figure>
<p>DOH! So close.  It seems the output is now limited by the width of the screen.  Looking at the help for Get-Table, I cannot see any option that allows me to make the table wider.  That led me to find this article.</p>
<p><a href="http://poshoholic.com/2010/11/11/powershell-quick-tip-creating-wide-tables-with-powershell/" target="_blank" rel="noopener">http://poshoholic.com/2010/11/11/powershell-quick-tip-creating-wide-tables-with-powershell/</a></p>
<p>It appears the solution is very simple.  Use out-string –width nnn.  Using a width of 200 and running the following command, I get what is shown below.</p>
<pre class="brush: bash; title: ; notranslate">.\listfw.ps1 | out-string –width 200 | out-file .\fw.txt</pre>
<p>&nbsp;</p>
<pre class="brush: plain; title: ; notranslate">
Name                                                                        Action Direction Protocol Local Ports Application Name
--------------------------------------------------------------------------- ------ --------- -------- ----------- --------------------------------------------------------------------------------
Citrix ICA (TCP-In)                                                                                   1494
Citrix IMA (TCP-In)                                                                                   2512
Citrix MFCOM (RPC)                                                                                    RPC         C:\Program Files (x86)\Citrix\system32\mfcom.exe
Citrix Print Service (RPC)                                                                            RPC         C:\Program Files (x86)\Citrix\system32\CpSvc.exe
Citrix Remote MFCOM DLLs (RPC)                                                                        RPC         C:\Windows\SysWOW64\dllhost.exe
Citrix Session Reliability (TCP-In)                                                                   2598        C:\Program Files (x86)\Citrix\XTE\bin\xte.exe
Citrix SSL Relay (TCP-In)                                                                             443         C:\Program Files (x86)\Citrix\XTE\bin\xte.exe
Citrix WI Configuration Manager (RPC)                                                                 RPC         C:\Program Files (x86)\Citrix\System32\ConfigMgrSvr.exe
Citrix XML Relay (TCP-In)                                                                             81          C:\Program Files (x86)\Citrix\System32\ctxxmlss.exe
Core Networking - Destination Unreachable (ICMPv6-In)                                                             System
Core Networking - Destination Unreachable Fragmentation Needed (ICMPv4-In)                                        System
Core Networking - DNS (UDP-Out)                                                                       *           C:\Windows\system32\svchost.exe
Core Networking - Dynamic Host Configuration Protocol (DHCP-In)                                       68          C:\Windows\system32\svchost.exe
Core Networking - Dynamic Host Configuration Protocol (DHCP-Out)                                      68          C:\Windows\system32\svchost.exe
Core Networking - Dynamic Host Configuration Protocol for IPv6(DHCPV6-In)                             546         C:\Windows\system32\svchost.exe
Core Networking - Dynamic Host Configuration Protocol for IPv6(DHCPV6-Out)                            546         C:\Windows\system32\svchost.exe
Core Networking - Group Policy (LSASS-Out)                                                            *           C:\Windows\system32\lsass.exe
Core Networking - Group Policy (NP-Out)                                                               *           System
Core Networking - Group Policy (TCP-Out)                                                              *           C:\Windows\system32\svchost.exe
Core Networking - Internet Group Management Protocol (IGMP-In)                                                    System
Core Networking - Internet Group Management Protocol (IGMP-Out)                                                   System
Core Networking - IPHTTPS (TCP-In)                                                                    IPHTTPS     System
Core Networking - IPHTTPS (TCP-Out)                                                                   *           C:\Windows\system32\svchost.exe
Core Networking - IPv6 (IPv6-In)                                                                                  System
Core Networking - IPv6 (IPv6-Out)                                                                                 System
Core Networking - Multicast Listener Done (ICMPv6-In)                                                             System
Core Networking - Multicast Listener Done (ICMPv6-Out)
Core Networking - Multicast Listener Query (ICMPv6-In)                                                            System
Core Networking - Multicast Listener Query (ICMPv6-Out)
Core Networking - Multicast Listener Report (ICMPv6-In)                                                           System
Core Networking - Multicast Listener Report (ICMPv6-Out)
Core Networking - Multicast Listener Report v2 (ICMPv6-In)                                                        System
Core Networking - Multicast Listener Report v2 (ICMPv6-Out)
Core Networking - Neighbor Discovery Advertisement (ICMPv6-In)                                                    System
Core Networking - Neighbor Discovery Advertisement (ICMPv6-Out)
Core Networking - Neighbor Discovery Solicitation (ICMPv6-In)                                                     System
Core Networking - Neighbor Discovery Solicitation (ICMPv6-Out)
Core Networking - Packet Too Big (ICMPv6-In)                                                                      System
Core Networking - Packet Too Big (ICMPv6-Out)
Core Networking - Parameter Problem (ICMPv6-In)                                                                   System
Core Networking - Parameter Problem (ICMPv6-Out)
Core Networking - Router Advertisement (ICMPv6-In)                                                                System
Core Networking - Router Advertisement (ICMPv6-Out)
Core Networking - Router Solicitation (ICMPv6-In)                                                                 System
Core Networking - Router Solicitation (ICMPv6-Out)
Core Networking - Teredo (UDP-In)                                                                     Teredo      C:\Windows\system32\svchost.exe
Core Networking - Teredo (UDP-Out)                                                                    *           C:\Windows\system32\svchost.exe
Core Networking - Time Exceeded (ICMPv6-In)                                                                       System
Core Networking - Time Exceeded (ICMPv6-Out)
DFS Management (DCOM-In)                                                                              135         C:\Windows\system32\svchost.exe
DFS Management (SMB-In)                                                                               445         System
DFS Management (TCP-In)                                                                               RPC         C:\Windows\system32\dfsfrsHost.exe
DFS Management (WMI-In)                                                                               RPC         C:\Windows\system32\svchost.exe
Remote Desktop - RemoteFX (TCP-In)                                                                    3389        C:\Windows\system32\svchost.exe
Remote Desktop (TCP-In)                                                                               3389        System
SQL Server (Citrix IMA)                                                                               *           C:\Program Files (x86)\Microsoft SQL Server\MSSQL10.CITRIX_METAFRAME\MSSQL\Bi...
SQL Server Browser (Citrix IMA)                                                                       *           C:\Program Files (x86)\Microsoft SQL Server\90\Shared\sqlbrowser.exe
Terminal Services - WMI (DCOM-In)                                                                     135         C:\Windows\system32\svchost.exe
Terminal Services - WMI (TCP-In)                                                                      RPC         C:\Windows\system32\svchost.exe
Terminal Services - WMI (WMI-Out)                                                                     *           C:\Windows\system32\svchost.exe
Terminal Services (NP-In)                                                                             445         System
Terminal Services (RPC)                                                                               RPC         C:\Windows\system32\svchost.exe
Terminal Services (RPC-EPMAP)                                                                         RPC-EPMap   C:\Windows\system32\svchost.exe
</pre>
<p>Now I have a report I can use. I can run this script before and after installing XenApp 6.5 and see what changes were made to the Windows Firewall rules.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.carlwebster.com/listing-windows-firewall-rules-using-microsoft-powershell/feed/</wfw:commentRss>
			<slash:comments>3</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">5010</post-id>	</item>
	</channel>
</rss>
