<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://powershell.com/cs/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Search results for 'app:weblogs' matching tags 'Scripting Guy!', 'security', and 'firewall'</title><link>http://powershell.com/cs/search/SearchResults.aspx?q=app:weblogs&amp;tag=Scripting+Guy!,security,firewall&amp;orTags=0&amp;o=DateDescending</link><description>Search results for 'app:weblogs' matching tags 'Scripting Guy!', 'security', and 'firewall'</description><dc:language>en-US</dc:language><generator>CommunityServer 2008.5 (Build: 30929.2835)</generator><item><title>PowerTip: Use PowerShell to Find Domain-Enabled Firewall Rules</title><link>http://powershell.com/cs/blogs/hey-scriptingguy/archive/2012/11/13/powertip-use-powershell-to-find-domain-enabled-firewall-rules.aspx</link><pubDate>Tue, 13 Nov 2012 06:00:00 GMT</pubDate><guid isPermaLink="false">f421715f-7aba-45f0-8a8d-44de5318a3a7:19985</guid><dc:creator>Anonymous</dc:creator><description>&lt;p&gt;&lt;strong&gt;Summary:&lt;/strong&gt;&amp;nbsp;Learn how to identify domain firewall rules by using Windows PowerShell&amp;nbsp;3.0 on Windows&amp;nbsp;8 or Windows Server&amp;nbsp;2012.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;img src="http://img.microsoft.com/library/media/1033/technet/images/scriptcenter/qanda/q-sm.jpg" alt="Hey, Scripting Guy! Question" /&gt;&amp;nbsp;&lt;/strong&gt;How can I find specific Domain profile firewall rules on my computer running Windows&amp;nbsp;8 or Windows Server&amp;nbsp;2012?&lt;/p&gt;
&lt;p style="padding-left:60px;"&gt;&lt;img src="http://img.microsoft.com/library/media/1033/technet/images/scriptcenter/qanda/a-sm.jpg" alt="Hey, Scripting Guy! Answer" /&gt;&amp;nbsp;Use the&amp;nbsp;&lt;strong&gt;Get-NetFirewallRule&lt;/strong&gt;&amp;nbsp;cmdlet and specify the&amp;nbsp;&lt;strong&gt;enabled&lt;/strong&gt;&lt;em&gt;&amp;nbsp;&lt;/em&gt;parameter as&amp;nbsp;&lt;strong&gt;true&lt;/strong&gt;&amp;nbsp;and filter on the domain profile, as shown here.&lt;/p&gt;
&lt;p style="padding-left:120px;"&gt;Get-NetFirewallRule -Enabled true | Where profile -eq &amp;#39;Domain&amp;#39;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.technet.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-76-18/7610.Dr.ScriptoForTips.jpg"&gt;&lt;img src="http://blogs.technet.com/resized-image.ashx/__size/150x0/__key/communityserver-blogs-components-weblogfiles/00-00-00-76-18/7610.Dr.ScriptoForTips.jpg" alt="" border="0" /&gt;&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.technet.com/aggbug.aspx?PostID=3531647" width="1" height="1" alt="" /&gt;</description></item><item><title>Use PowerShell to Create New Windows Firewall Rules</title><link>http://powershell.com/cs/blogs/hey-scriptingguy/archive/2012/11/13/use-powershell-to-create-new-windows-firewall-rules.aspx</link><pubDate>Tue, 13 Nov 2012 06:00:00 GMT</pubDate><guid isPermaLink="false">f421715f-7aba-45f0-8a8d-44de5318a3a7:19986</guid><dc:creator>Anonymous</dc:creator><description>&lt;p&gt;&lt;strong&gt;Summary:&lt;/strong&gt; Microsoft Scripting Guy, Ed Wilson, shows how to use Windows PowerShell to create new Windows Firewall rules on local and remote systems.&lt;/p&gt;
&lt;p&gt;Microsoft Scripting Guy, Ed Wilson, is here. Today, we are off to Europe. The Scripting Wife and I are actually on separate flights&amp;mdash;it&amp;rsquo;s the way the airline miles worked out for the flight. Luckily, the Scripting Wife is an excellent traveler. When I was working in Vienna a few years ago, she flew into Frankfurt, hopped a train to Vienna, and navigated the local S-Bahn trains from the Ost-Bahnhoff to the hotel without incident.&lt;/p&gt;
&lt;p&gt;Anyway, from Frankfurt, once we are all there, we hop a train to Dortmond, Germany, where we will meet with Klaus Schulte. Klaus, as you may know, was the winner of the Scripting Games, and he has written several guest Hey, Scripting Guy! Blog posts. Neither the Scripting Wife nor myself has been to Dortmond, and we are looking forward to hanging out with Klaus, taking pictures, and of course, talking about Windows PowerShell.&lt;/p&gt;
&lt;h2&gt;Enable firewall rules with Windows PowerShell&lt;/h2&gt;
&lt;p&gt;I know why we do it, but dude, I still like to use Ping to see if a computer is up or down. I know I can use Windows PowerShell and do something like &lt;strong&gt;Test-WSMan&lt;/strong&gt; to see if WinRM works, but old habits die hard. By default, on certain profiles, and on certain versions of the operating system, the Ping command is disabled. It really makes life difficult in the early hours of the morning when I tend to forget these sorts of things. So, I like to explicitly ensure that Ping is permitted through Windows Firewall. Once I have done this, and a machine does not respond to Ping, I know I need to do something else.&lt;/p&gt;
&lt;p&gt;Unfortunately, while I can use the &lt;strong&gt;Get-NetFireWallRule&lt;/strong&gt; cmdlet to retrieve information about scope and status of a firewall rule, it does not display what the actual rule itself is or does. This means that, for example, I cannot use &lt;strong&gt;Get-NetFireWallRule&lt;/strong&gt; to retrieve a firewall rule and use it as a pattern when it comes to creating a new rule. In addition, it means that I cannot use the GUI tool to create a new firewall rule, use the &lt;strong&gt;Get-NetFireWallRule&lt;/strong&gt; cmdlet to obtain the actual rules themselves, and then use that to create a new rule. &lt;strong&gt;Get-NetFireWallRule&lt;/strong&gt; is useful for auditing but not for system configuration.&lt;/p&gt;
&lt;h2&gt;Create a new firewall rule&lt;/h2&gt;
&lt;p&gt;To create a new firewall rule that permits the Ping command, I first import the NetSecurity module. Next, I use the &lt;strong&gt;New-NetFirewallRule&lt;/strong&gt; cmdlet to create the new firewall rule. The problem with this is that I basically have to know what I am doing &amp;hellip; specifically. If, for example, I do not know that a Ping is ICMPv4 protocol, and specifically ICMPType 8, then I have no chance of creating a new firewall rule. This is where the GUI tool is a bit more friendly&amp;mdash;rather than having to look up the ICMPTypes, they are available through the ICMP type page. This is shown here.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.technet.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-76-18/2043.hsg_2D00_11_2D00_13_2D00_12_2D00_01.png"&gt;&lt;img title="Image of Customize ICMP Settings dialog box" src="http://blogs.technet.com/resized-image.ashx/__size/450x0/__key/communityserver-blogs-components-weblogfiles/00-00-00-76-18/2043.hsg_2D00_11_2D00_13_2D00_12_2D00_01.png" alt="Image of Customize ICMP Settings dialog box" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Here again, even the GUI tool does not actually list the ICMP type. So to get this information, I need to either already know it (Hey, I wrote a book on &lt;a href="http://www.amazon.com/Network-Monitoring-Analysis-Protocol-Troubleshooting/dp/0130264954" target="_blank"&gt;Network Monitoring and Analysis&lt;/a&gt;), or I need to look it up by using Ping.&lt;/p&gt;
&lt;p&gt;I recommend using the Windows PowerShell cmdlet to create the firewall rule, and then inspecting the rule in the Windows Firewall with Advanced Security tool. Here is the rule I came up with to permit Ping on network interfaces with the ANY profile. (Note that I could use DOMAIN or PRIVATE profiles as well.)&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;Import-Module NetSecurity&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;New-NetFirewallRule -Name Allow_Ping -DisplayName &amp;quot;Allow Ping&amp;quot;`&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp; -Description &amp;quot;Packet Internet Groper ICMPv4&amp;quot; `&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp; -Protocol ICMPv4 -IcmpType 8 -Enabled True -Profile Any -Action Allow&amp;nbsp;&lt;/p&gt;
&lt;h2&gt;Deploy the rule to all my Windows Server&amp;nbsp;2012 and Windows&amp;nbsp;8 machines&lt;/h2&gt;
&lt;p&gt;The first thing I need to do is to find all of my computers running Windows Server&amp;nbsp;2012 and Windows&amp;nbsp;8. I created a specific filter for the &lt;strong&gt;Get-ADComputer&lt;/strong&gt; cmdlet that returns only these types of computers. I also specify Admin credentials to the &lt;strong&gt;Get-Credential&lt;/strong&gt; cmdlet. This is shown here.&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;Import-Module NetSecurity, ActiveDirectory&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;$cred = Get-Credential -Credential iammred\administrator&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;$cn = Get-ADComputer -Properties operatingsystem -Filter `&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;quot;Operatingsystem -like &amp;#39;windows 8 *&amp;#39; -OR OperatingSystem -like &amp;#39;* 2012 *&amp;#39;&amp;quot;&lt;/p&gt;
&lt;p&gt;Now, I create a CIM session to each of these computers. When I do this, I specify the name of the computer and the credentials to use to make the connection. I do not worry if computers are offline when calling the command because it only connects with online machines. It simplifies the code. This appears here.&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;$CIM = New-CimSession -ComputerName $cn.name -Credential $cred&lt;/p&gt;
&lt;p&gt;Next, I use the same &lt;strong&gt;New-NetFirewallRule&lt;/strong&gt; command I used before&amp;mdash;only this time I add that I want to use the CIM sessions in the $cim variable. Here is the code.&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;New-NetFirewallRule -Name Allow_Ping -DisplayName &amp;quot;Allow Ping&amp;quot;`&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp; -Description &amp;quot;Packet Internet Groper ICMPv4&amp;quot; `&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp; -Protocol ICMPv4 -IcmpType 8 -Enabled True -Profile Any -Action Allow `&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp; -CimSession $cim&lt;/p&gt;
&lt;h2&gt;Verify that the changes took place&lt;/h2&gt;
&lt;p&gt;Because I already have the CIM sessions in the $CIM variable, I can use that with the &lt;strong&gt;Get-NetFirewallRule&lt;/strong&gt; cmdlet to verify that the remote servers and workstations have received the new firewall rule. This command is shown here.&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;Get-NetFirewallRule -DisplayName &amp;quot;Allow Ping&amp;quot; -CimSession $cim |&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp; Select PSComputerName, name, enabled, profile, action |&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp; Format-Table -AutoSize&lt;/p&gt;
&lt;p&gt;&amp;nbsp;The command and the associated output are shown here.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.technet.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-76-18/3566.hsg_2D00_11_2D00_13_2D00_12_2D00_02.png"&gt;&lt;img title="Image of command output" src="http://blogs.technet.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-00-76-18/3566.hsg_2D00_11_2D00_13_2D00_12_2D00_02.png" alt="Image of command output" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;I also want to verify that the Pings themselves will take place. Now, remember that the &lt;strong&gt;Get-ADComputer&lt;/strong&gt; command returned some computers that were offline. But the $CIM variable contains CIM sessions to each computer that is obviously online. Unfortunately, the &lt;strong&gt;Test-Connection&lt;/strong&gt; cmdlet does not accept a CIM session object, but that does not matter because it does accept an array of computer names. With auto array expansion, I can get the computer names from the variable containing all of the CIM sessions easily. Here is the command to which I arrived.&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;Test-Connection -ComputerName $cim.computername -BufferSize 15 -Count 1&lt;/p&gt;
&lt;p&gt;The command and associated output are shown here.&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;PS C:\&amp;gt; Test-Connection -ComputerName $cim.computername -BufferSize 15 -Count 1&amp;nbsp;&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;Source&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Destination&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; IPV4Address&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; IPV6Address&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;------&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; -----------&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; -----------&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; -----------&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;EDLT&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; DC2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 192.168.0.102&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;EDLT&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; DC3&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 192.168.0.103&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;EDLT&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; DC4&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 192.168.0.104&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;EDLT&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; EDLT&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 192.168.3.228&amp;nbsp;&amp;nbsp;&amp;nbsp; fe80::bd2d:5283:5572:5e77%19&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;EDLT&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; HYPERV2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 192.168.0.46&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;EDLT&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; HYPERV3&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 192.168.0.43&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;EDLT&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; SQL1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 192.168.0.150&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;EDLT&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; WDS1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 192.168.0.152&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;EDLT&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; WEB1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 192.168.0.54&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Sweet, it worked! Join me tomorrow when I will talk about more way-cool Windows PowerShell stuff.&lt;/p&gt;
&lt;p&gt;I invite you to follow me on &lt;a href="http://bit.ly/scriptingguystwitter" target="_blank"&gt;Twitter&lt;/a&gt; and &lt;a href="http://bit.ly/scriptingguysfacebook" target="_blank"&gt;Facebook&lt;/a&gt;. If you have any questions, send email to me at &lt;a href="mailto:scripter@microsoft.com" target="_blank"&gt;scripter@microsoft.com&lt;/a&gt;, or post your questions on the &lt;a href="http://bit.ly/scriptingforum" target="_blank"&gt;Official Scripting Guys Forum&lt;/a&gt;. See you tomorrow. Until then, peace.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Ed Wilson, Microsoft Scripting Guy&lt;/strong&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.technet.com/aggbug.aspx?PostID=3531648" width="1" height="1" alt="" /&gt;</description></item><item><title>Weekend Scripter: Playing Around with Windows Firewall</title><link>http://powershell.com/cs/blogs/hey-scriptingguy/archive/2012/10/28/weekend-scripter-playing-around-with-windows-firewall.aspx</link><pubDate>Sun, 28 Oct 2012 05:00:00 GMT</pubDate><guid isPermaLink="false">f421715f-7aba-45f0-8a8d-44de5318a3a7:19742</guid><dc:creator>Anonymous</dc:creator><description>&lt;p&gt;&lt;b&gt;Summary&lt;/b&gt;: Microsoft Scripting Guy, Ed Wilson, shows how to use Windows PowerShell to work with Windows Firewall on Windows 8&amp;nbsp;and Windows Server&amp;nbsp;2012.&lt;/p&gt;
&lt;p&gt;Microsoft Scripting Guy, Ed Wilson, is here. The Scripting Wife and I returned home from the &lt;a href="http://powershellsaturday.com/003/" target="_blank"&gt;Windows PowerShell Saturday #003 event&lt;/a&gt; in Atlanta, Georgia, last night, and we were exhausted&amp;mdash;happy, but exhausted. The event was packed, and Mark Schill and the crew did a fantastic job organizing a flawless Windows PowerShell Saturday. Well done. All the sessions were marked high to extremely high by attendees.&lt;/p&gt;
&lt;p&gt;If you follow the Scripting Wife on Facebook or Twitter, you know I have not been able to eat or drink anything hot for a week&amp;mdash;that means no hot tea&amp;mdash;and it has been driving me crazy. So, I am sitting on the lanai sipping a cool glass of water&amp;mdash;not quite the same as English Breakfast Tea&amp;mdash;not by a long shot.&lt;/p&gt;
&lt;p&gt;Anyway, one of the things I have wanted to play with is the cmdlets for Windows Firewall. With nothing on the agenda but a murder mystery, written by my good friend and mentor &lt;a href="http://elizabethterrell.com/" target="_blank"&gt;Jaden Terrell&lt;/a&gt;, and a glass of cool water, today is the day.&lt;/p&gt;
&lt;h2&gt;Windows&amp;nbsp;8 Firewall cmdlets&amp;mdash;a quick look&lt;/h2&gt;
&lt;p&gt;I am a huge fan of Windows Firewall because it works well, provides a measure of in-depth security, and comes with the operating system. In fact, I rarely find firewall-related issues, and, therefore, I do not turn it off&amp;mdash;in fact, I leave it running on both the desktop and the server.&lt;/p&gt;
&lt;p&gt;The first thing to do when working with the firewall is to determine the network connection profile because this determines the way the firewall policies work. In Windows&amp;nbsp;8 and Windows Server&amp;nbsp;2012, the &lt;b&gt;Get-NetConnectionProfile&lt;/b&gt; cmdlet is extremely useful for this task. I first enumerate my network adapters, find the ones that are up, and then get the network connection profile. The commands are shown here.&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&lt;b&gt;Note&lt;/b&gt; &amp;nbsp;&amp;nbsp;I use the error action of 0 to remove errors about connection profiles for virtual adapters that are not connected to a network but are considered to be up. I also use the simple &lt;b&gt;Where-Object&lt;/b&gt; syntax (&lt;b&gt;?&lt;/b&gt; is an alias for the &lt;b&gt;Where-Object&lt;/b&gt; cmdlet). Keep in mind when working with Windows PowerShell cmdlets that you have tab completion, and it greatly simplifies typing commands.&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;PS C:\&amp;gt; Get-NetAdapter | ? status -EQ &amp;#39;up&amp;#39; | Get-NetConnectionProfile &amp;ndash;ea 0&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;Name&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : Unidentified network&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;InterfaceAlias&amp;nbsp;&amp;nbsp; : vEthernet (InternalSwitch)&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;InterfaceIndex&amp;nbsp;&amp;nbsp; : 19&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;NetworkCategory&amp;nbsp; : Public&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;IPv4Connectivity : NoTraffic&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;IPv6Connectivity : NoTraffic&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;Name&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : iammred.net&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;InterfaceAlias&amp;nbsp;&amp;nbsp; : vEthernet (External Switch)&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;InterfaceIndex&amp;nbsp;&amp;nbsp; : 23&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;NetworkCategory&amp;nbsp; : DomainAuthenticated&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;IPv4Connectivity : Internet&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;IPv6Connectivity : LocalNetwork&lt;/p&gt;
&lt;p&gt;To find the names and the status of the various Windows Firewall profiles, I use the &lt;b&gt;Get-NetFirewallProfile&lt;/b&gt; cmdlet. I pipe the results to the &lt;b&gt;Format-Table&lt;/b&gt; cmdlet (&lt;b&gt;ft&lt;/b&gt; is the alias), and I choose only the name and the enabled properties. I then use the &lt;b&gt;autosize&lt;/b&gt;&lt;i&gt; &lt;/i&gt;switch to tighten up the display. The command and results are shown here.&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;PS C:\&amp;gt; Get-NetFirewallProfile | ft name, enabled -auto&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;name&amp;nbsp;&amp;nbsp;&amp;nbsp; Enabled&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;----&amp;nbsp;&amp;nbsp;&amp;nbsp; -------&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;Domain&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; True&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;Private&amp;nbsp;&amp;nbsp;&amp;nbsp; True&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;Public&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; True&lt;/p&gt;
&lt;p&gt;Now for the first frustration: Except for the &lt;i&gt;public&lt;/i&gt; network category, the value of the network category and the name of the firewall profile do not match up, and, therefore, it prevents piping. In this case, I cannot use &lt;b&gt;Get-NetworkAdapter&lt;/b&gt; to get my network adapters, pipe it to the &lt;b&gt;Get-NetConnectionProfile&lt;/b&gt; cmdlet, and then pipe it to the &lt;b&gt;Get-NetFireWallProfile&lt;/b&gt; cmdlet. However, I can focus on the details of a specific firewall profile. Here are the details of the public network profile.&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;PS C:\&amp;gt; Get-NetFirewallProfile public&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;Name&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : Public&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;Enabled&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : True&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;DefaultInboundAction&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : NotConfigured&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;DefaultOutboundAction&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : NotConfigured&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;AllowInboundRules&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : NotConfigured&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;AllowLocalFirewallRules&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : NotConfigured&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;AllowLocalIPsecRules&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : NotConfigured&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;AllowUserApps&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : NotConfigured&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;AllowUserPorts&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : NotConfigured&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;AllowUnicastResponseToMulticast : NotConfigured&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;NotifyOnListen&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : True&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;EnableStealthModeForIPsec&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : NotConfigured&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;LogFileName&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : %systemroot%\system32\LogFiles\Firewall\pfirewall&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; log&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;LogMaxSizeKilobytes&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : 4096&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;LogAllowed&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : False&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;LogBlocked&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : False&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;LogIgnored&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : NotConfigured&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;DisabledInterfaceAliases&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;: {NotConfigured}&lt;/p&gt;
&lt;p&gt;&lt;br /&gt; The cool thing is that the &lt;b&gt;Get-NetFirewallProfile&lt;/b&gt; cmdlet accepts an array for the profile name. Therefore, I can use a command something like the one appearing here.&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;Get-NetFirewallProfile domain,private,public&lt;/p&gt;
&lt;p&gt;Even better, the &lt;b&gt;Get-NetFirewallProfile&lt;/b&gt; cmdlet accepts wildcards. Therefore, I can use a command something like this one.&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;Get-NetFirewallProfile d*,p*&lt;/p&gt;
&lt;p&gt;One problem with the firewall cmdlets is that they are all part of the massive NetSecurity module&amp;mdash;a module that supplies 84 cmdlets and functions. I found this out by using the command shown here.&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;PS C:\&amp;gt; (gcm -Module netsecurity).count&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;84&lt;/p&gt;
&lt;p&gt;Further, there are no aliases for any of the commands in the NetSecurity module. This is revealed by the command shown here.&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;gcm -Module netsecurity | % {gal -Definition $_.name -ea 0}&lt;/p&gt;
&lt;p&gt;Besides no aliases for the firewall cmdlets, all of the names are pretty long, and due to the naming convention, tab expansion for the cmdlet names is not very efficient either. The 27 cmdlets appear here (sorted by name because the verb and noun are not exposed through &lt;b&gt;Get-Command&lt;/b&gt;).&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;PS C:\&amp;gt; gcm -noun *fire* | sort name | select name&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;Name&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;----&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;Copy-NetFirewallRule&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;Disable-NetFirewallRule&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;Enable-NetFirewallRule&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;Get-NetFirewallAddressFilter&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;Get-NetFirewallApplicationFilter&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;Get-NetFirewallInterfaceFilter&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;Get-NetFirewallInterfaceTypeFilter&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;Get-NetFirewallPortFilter&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;Get-NetFirewallProfile&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;Get-NetFirewallRule&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;Get-NetFirewallSecurityFilter&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;Get-NetFirewallServiceFilter&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;Get-NetFirewallSetting&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;New-NetFirewallRule&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;Remove-NetFirewallRule&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;Rename-NetFirewallRule&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;Set-NetFirewallAddressFilter&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;Set-NetFirewallApplicationFilter&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;Set-NetFirewallInterfaceFilter&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;Set-NetFirewallInterfaceTypeFilter&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;Set-NetFirewallPortFilter&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;Set-NetFirewallProfile&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;Set-NetFirewallRule&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;Set-NetFirewallSecurityFilter&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;Set-NetFirewallServiceFilter&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;Set-NetFirewallSetting&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;Show-NetFirewallRule&lt;/p&gt;
&lt;p&gt;Because of the naming convention, when using tab expansion, I have to type &lt;b&gt;NetFirewall&lt;/b&gt;, and then a letter, such as &lt;b&gt;P&lt;/b&gt; or &lt;b&gt;R&lt;/b&gt; or &lt;b&gt;S&lt;/b&gt;, to get close to the actual function name. If I type &lt;b&gt;NetF&lt;/b&gt; and press tab, I have to cycle through the commands to find the function name I&amp;#39;m looking for.&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&lt;b&gt;Note&lt;/b&gt; &amp;nbsp;&amp;nbsp;If your duties require you to spend much time working with the firewall cmdlets, I recommend that you create your own series of aliases for the functions with which you regularly work. Store these aliases in a module that you can load on demand or in your profile, if you wish to have them at hand.&lt;/p&gt;
&lt;p&gt;That is a quick overview of the firewall functions. Hope all is well with you, and happy scripting.&lt;/p&gt;
&lt;p&gt;I invite you to follow me on &lt;a href="http://bit.ly/scriptingguystwitter" target="_blank"&gt;Twitter&lt;/a&gt; and &lt;a href="http://bit.ly/scriptingguysfacebook" target="_blank"&gt;Facebook&lt;/a&gt;. If you have any questions, send email to me at &lt;a href="mailto:scripter@microsoft.com" target="_blank"&gt;scripter@microsoft.com&lt;/a&gt;, or post your questions on the &lt;a href="http://bit.ly/scriptingforum" target="_blank"&gt;Official Scripting Guys Forum&lt;/a&gt;. See you tomorrow. Until then, peace.&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Ed Wilson, Microsoft Scripting Guy&lt;/b&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.technet.com/aggbug.aspx?PostID=3528716" width="1" height="1" alt="" /&gt;</description></item><item><title>Use PowerShell for Network Host and Port Discovery Sweeps</title><link>http://powershell.com/cs/blogs/hey-scriptingguy/archive/2012/07/02/use-powershell-for-network-host-and-port-discovery-sweeps.aspx</link><pubDate>Mon, 02 Jul 2012 05:00:00 GMT</pubDate><guid isPermaLink="false">f421715f-7aba-45f0-8a8d-44de5318a3a7:17371</guid><dc:creator>Anonymous</dc:creator><description>&lt;p&gt;&lt;b&gt;Summary&lt;/b&gt;: Guest blogger, Niklas Goude, discusses using Windows PowerShell to perform ping sweeps and port scans on a connected network.&lt;/p&gt;
&lt;p&gt;Microsoft Scripting Guy, Ed Wilson, is here. This week we have guest blogger Niklas Goude. Before we get to Niklas, I want to mention that you should mark your calendars for September 15, 2012 because that is the date that the second Windows PowerShell Saturday event occurs. It will be held in Charlotte, North Carolina. Attendance is limited, so keep your ears attuned for when registration opens. We will have three tracks and the event will be a lot of fun.&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;Niklas Goude is a Security Consultant at TrueSec and an MVP in Windows PowerShell. In addition to his work performing security assessments for a variety of clients, he also has extensive experience in using Windows PowerShell to automate and implement Windows environments. He has been speaking at TechDays; SharePoint conferences in the U.S., Australia, and New Zealand; and other events and conferences. He is the author of two books about Windows PowerShell, and he shares his knowledge at &lt;a href="http://www.powershell.nu/" target="_blank"&gt;PowerShell.nu&lt;/a&gt;. He is a member of the TrueSec Expert Team, an independent, elite team of security and infrastructure consultants that operates all over the world. The security team at TrueSec performs various tasks and services related to IT security such as code review, security health checks, and penetration testing. TrueSec also delivers top-notch training sessions in advanced IT security. Check out the &lt;a href="http://www.truesec.com/" target="_blank"&gt;TruSec&lt;/a&gt; website for additional information.&lt;/p&gt;
&lt;p&gt;Now, without further ado, here is Niklas&amp;hellip;&lt;/p&gt;
&lt;p&gt;Penetration testing is an important part of improving security in any network environment. A hacker usually only needs to find very few weaknesses (even only one) to compromise important IT systems. An important task for an IT administrator is to identify potential weaknesses and mitigate them.&lt;/p&gt;
&lt;p&gt;This is the first blog in a weekly series of five where we will talk about basic penetration testing techniques and how they affect misconfigured systems. The series will cover everything from initial network reconnaissance techniques and brute force attacks to advanced extraction of registry secrets to assess dangerous system dependencies.&lt;/p&gt;
&lt;p&gt;The key learning point is to demonstrate how you can use Windows PowerShell to accomplish almost any task no matter the subject. The secondary learning point is to make you aware of common security issues and misconfigurations that may occur in Microsoft infrastructures today. One important thing to keep in mind is that the vulnerabilities we are looking for exist simply because of misconfigurations made by administrators, such as weak passwords, system dependencies, misconfigurations, and more. I hope you will learn and enjoy!&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&lt;b&gt;Note&lt;/b&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;Today&amp;rsquo;s blog discusses using Windows PowerShell to perform network discovery. On some networks, use of such techniques is expressly disallowed except for specifically authorized teams and individuals. You must ensure that you have permission to perform the techniques described here prior to using such techniques at work. This also is a good time to emphasize the importance of proper network security configuration. For help with security configuration of your computer, see the &lt;a href="http://www.microsoft.com/security/default.aspx" target="_blank"&gt;Microsoft Safety &amp;amp; Security Center&lt;/a&gt;.&lt;/p&gt;
&lt;h2&gt;Part&amp;nbsp;1: Scanning&lt;/h2&gt;
&lt;p&gt;Scanning for IP addresses, MAC addresses, host names, and open ports is a way of finding the available computers on a network and finding out which service each computer publishes. In this blog, we will talk about how this can be performed by using Windows PowerShell.&lt;/p&gt;
&lt;h3&gt;Scenario&lt;/h3&gt;
&lt;p&gt;This scenario is based on a Windows domain environment that consists of three machines:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;DC01: domain controller&lt;/li&gt;
&lt;li&gt;SRV01: SQL Server and IIS&lt;/li&gt;
&lt;li&gt;SP01: SharePoint 2010, SQL Server, and IIS&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;In addition, we have a client on the same network as the domain however the client is not a member of the domain. Each command in this scenario is executed from the client.&lt;/p&gt;
&lt;h3&gt;Configuration&lt;/h3&gt;
&lt;p&gt;The servers are manually installed by using the default settings. The servers use the Windows Firewalls default settings. The recommended internal firewall design is described in the following Microsoft TechNet Security Bulletin: &lt;a href="http://technet.microsoft.com/en-us/library/cc700827.aspx" target="_blank"&gt;Internal Firewall Design&lt;/a&gt;.&lt;/p&gt;
&lt;h3&gt;Code&lt;/h3&gt;
&lt;p&gt;The first step in scanning the network for IP addresses, host names, and open ports is to determine which network we are currently sitting on. The simplest way to do this is to use &lt;b&gt;ipconfig&lt;/b&gt;. As you already know, Windows PowerShell has full support for running executables.&lt;/p&gt;
&lt;p&gt;Simply type &lt;b&gt;ipconfig&lt;/b&gt; to find out which network you are on. If you are running Windows PowerShell&amp;nbsp;3.0, you can also use the new &lt;b&gt;Get-NetIPAddress&lt;/b&gt; cmdLlet.&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;PS &amp;gt; ipconfig&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;Windows IP Configuration&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;Ethernet adapter Wired Ethernet Connection 2:&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp;Connection-specific DNS Suffix . :&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp;Link-local IPv6 Address . . . . . : fe81::3314:cf47:dbc2:935c%11&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp;IPv4 Address. . . . . . . . . . . : 10.0.0.100&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp;Subnet Mask . . . . . . . . . . . : 255.0.0.0&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp;Default Gateway . . . . . . . . . : 10.0.0.1&lt;/p&gt;
&lt;p&gt;This example tells us that our IP address is 10.0.0.100 and the subnet is 255.0.0.0. With this information, we can perform a ping sweep on the network to find out if any hosts are reachable. We could, of course, achieve this by using ping.exe. However, there are more efficient ways to perform ping sweeps in a Windows network by using Windows PowerShell. One way is to use the &lt;b&gt;Test-Connection&lt;/b&gt; cmdlet, which returns a &lt;b&gt;Win32_PingStatus&lt;/b&gt; object that we can investigate in Windows PowerShell. We can also create an instance of System.Net.Networkinformation.Ping by using the &lt;b&gt;New-Object&lt;/b&gt; cmdlet. This is the approach we&amp;rsquo;ll focus on. The following example demonstrates how to create an instance of System.Net.Networkinformation.Ping.&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;PS &amp;gt; $ping = New-Object System.Net.Networkinformation.ping&lt;/p&gt;
&lt;p&gt;The &lt;b&gt;Ping&lt;/b&gt; class supports a method called &lt;b&gt;Send()&lt;/b&gt;, which we can use to send an Internet Control Message Protocol (ICMP) echo request to a computer by simply specifying an IP address. The following example demonstrates how to send an ICMP echo request to 10.0.0.2.&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;PS &amp;gt; $ping.Send(&amp;quot;10.0.0.2&amp;quot;)&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;Status&amp;nbsp;&amp;nbsp;&amp;nbsp; : Success&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;Address&amp;nbsp;&amp;nbsp; &amp;nbsp;: 10.0.0.2&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;RoundtripTime : 0&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;Options&amp;nbsp;&amp;nbsp; &amp;nbsp;: System.Net.NetworkInformation.PingOptions&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;Buffer&amp;nbsp;&amp;nbsp;&amp;nbsp; : {97, 98, 99, 100...}&lt;/p&gt;
&lt;p&gt;If the computer responds, the status property is set to Success as shown in this example. It&amp;rsquo;s also possible to add a timeout by using a different overload definition. The timeout specifies the maximum number of milliseconds to wait for the ICMP echo reply message. The following example demonstrates how to ping 10.0.0.10 and wait for 500 milliseconds.&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;PS &amp;gt; $ping.Send(&amp;quot;10.0.0.10&amp;quot;, 500)&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;Status&amp;nbsp;&amp;nbsp;&amp;nbsp; : TimedOut&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;Address&amp;nbsp;&amp;nbsp; &amp;nbsp;:&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;RoundtripTime : 0&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;Options&amp;nbsp;&amp;nbsp; &amp;nbsp;:&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;Buffer&amp;nbsp;&amp;nbsp;&amp;nbsp; : {}&lt;/p&gt;
&lt;p&gt;If we wanted to perform a ping sweep on multiple computers, we could simply take advantage of the Windows PowerShell pipeline support, and pipe any number of given IP addresses to the &lt;b&gt;Send()&lt;/b&gt; method.&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;PS &amp;gt; &amp;quot;10.0.0.2&amp;quot;,&amp;quot;10.0.0.3&amp;quot; | ForEach-Object { $ping.Send($_, 500) }&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;Status&amp;nbsp;&amp;nbsp;&amp;nbsp; : Success&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;Address&amp;nbsp;&amp;nbsp; &amp;nbsp;: 10.0.0.2&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;RoundtripTime : 0&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;Options&amp;nbsp;&amp;nbsp; &amp;nbsp;: System.Net.NetworkInformation.PingOptions&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;Buffer&amp;nbsp;&amp;nbsp;&amp;nbsp; : {97, 98, 99, 100...}&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;Status&amp;nbsp;&amp;nbsp;&amp;nbsp; : Success&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;Address&amp;nbsp;&amp;nbsp; &amp;nbsp;: 10.0.0.3&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;RoundtripTime : 0&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;Options&amp;nbsp;&amp;nbsp; &amp;nbsp;: System.Net.NetworkInformation.PingOptions&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;Buffer&amp;nbsp;&amp;nbsp;&amp;nbsp; : {97, 98, 99, 100...}&lt;/p&gt;
&lt;p&gt;Now that we know how to perform a simple ping sweep by using Windows PowerShell, let&amp;rsquo;s take a look at how to use Windows PowerShell to resolve a host name.&lt;/p&gt;
&lt;p&gt;The &lt;b&gt;System.Net.DNS&lt;/b&gt; class contains a static method, &lt;b&gt;GetHostEntry()&lt;/b&gt;, which we can use to ask the DNS server for the host name that is associated with a given IP address.&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;PS &amp;gt; [Net.DNS]::GetHostEntry(&amp;quot;10.0.0.3&amp;quot;)&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;HostName&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Aliases&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; AddressList&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;--------&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;-------&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; -----------&amp;nbsp; &lt;br /&gt; SRV01.hacme.local&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;{}&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;{10.0.0.3}&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;SRV01.hacme.local&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;{}&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;{10.0.0.3&lt;/p&gt;
&lt;p&gt;It is also possible to ask the DNS server for the host name &lt;b&gt;Async&lt;/b&gt; by using the &lt;b&gt;BeginGetHostEntry() &lt;/b&gt;and the &lt;b&gt;EndGetHostEntry()&lt;/b&gt; methods that are supported by &lt;b&gt;System.Net.DNS&lt;/b&gt;.&lt;/p&gt;
&lt;p&gt;Next, let us look at how to determine which ports are open on a system. The &lt;b&gt;System.Net.Sockets.TcpClient&lt;/b&gt; class supports the &lt;b&gt;Connect()&lt;/b&gt; method, which we can use to connect to a given IP address and port. First we create an instance to &lt;b&gt;System.Net.Sockets.TcpClient&lt;/b&gt;.&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;PS &amp;gt; $tcpClient = New-Object System.Net.Sockets.TCPClient&lt;/p&gt;
&lt;p&gt;Next, we use the &lt;b&gt;Connect()&lt;/b&gt; method and try to connect to a specific IP address and port. In the following example, we test if port 445 is open. Port 445 is the SMB port. If the connection is successful, the &lt;b&gt;Connected&lt;/b&gt; property is set to True as shown here:&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;PS &amp;gt; $tcpClient = New-Object System.Net.Sockets.TCPClient&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;PS &amp;gt; $tcpClient.Connect(&amp;quot;10.0.0.2&amp;quot;,445)&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;PS &amp;gt; $tcpClient.Connected&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;True&lt;/p&gt;
&lt;p&gt;If the connection fails, an error message is displayed and the &lt;b&gt;Connected&lt;/b&gt; property is False.&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;PS &amp;gt; $tcpClient.Connect(&amp;quot;10.0.0.2&amp;quot;,1234)&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;Exception calling &amp;quot;Connect&amp;quot; with &amp;quot;2&amp;quot; argument(s):&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;quot;A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond 10.0.0.2:1234&amp;quot;&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;At line:1 char:1+ $tcpClient.Connect(&amp;quot;10.0.0.2&amp;quot;,1234)&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp; + CategoryInfo&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : NotSpecified: (:) [], MethodInvocationException&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp; + FullyQualifiedErrorId : SocketException&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;PS &amp;gt; $tcpClient.Connected&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;False&lt;/p&gt;
&lt;p&gt;It is also possible to test the port&amp;rsquo;s Async by using the &lt;b&gt;BeginConnect()&lt;/b&gt; method.&lt;/p&gt;
&lt;p&gt;These are the basic steps that we need to perform a network scan by using Windows PowerShell. The nice thing about Windows PowerShell is that we can reuse the code by placing it in a function and simply calling the function instead of typing the code every time we want to perform a network scan.&lt;/p&gt;
&lt;p&gt;The following example demonstrates the &lt;b&gt;Invoke-TSPingSweep&lt;/b&gt; function in action.&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;PS &amp;gt; Invoke-TSPingSweep -StartAddress 10.0.0.1 -EndAddress 10.0.0.10 -ResolveHost -ScanPort&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;IPAddress&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;HostName&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;Ports&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;---------&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;--------&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;-----&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;10.0.0.2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; DC01.hacme.local&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;{53, 139, 389, 445...}&amp;nbsp;&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;10.0.0.3&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; SRV01.hacme.local&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {21, 80, 139, 445...}&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;10.0.0.10&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;SP01.hacme.local&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;{80, 139, 445}&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/p&gt;
&lt;p&gt;The function uses the code described in this post and supports the following parameters:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;StartAddress&lt;/li&gt;
&lt;li&gt;EndAddress&lt;/li&gt;
&lt;li&gt;ResolveHost&lt;/li&gt;
&lt;li&gt;ScanPort&lt;/li&gt;
&lt;li&gt;Ports&lt;/li&gt;
&lt;li&gt;Timeout&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Using the functionality of Windows PowerShell makes it very easy to search for specific ports that are returned from a network scan to determine if a computer is running a specific service. For example, if we wanted to find all computers running SQL Server, we could simply store the output in a variable and use the &lt;b&gt;Where-Object&lt;/b&gt; cmdlet to retrieve each object where the Port 1433 is open.&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;PS &amp;gt; $pingSweep = Invoke-TSPingSweep -StartAddress 10.0.0.1 -EndAddress 10.0.0.10 -ResolveHost -ScanPort&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&lt;br /&gt; PS &amp;gt; $pingSweep | Where-Object { $_.Ports -eq &amp;quot;1433&amp;quot; }&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;IPAddress&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;HostName&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;Ports&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;---------&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;--------&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;-----&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;10.0.0.3&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; SRV01.hacme.local&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {21, 80, 139, 445...}&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;PS &amp;gt; $pingSweep | Where-Object { $_.Ports -eq 80 }&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;IPAddress&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;HostName&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Ports&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;---------&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;--------&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;-----&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;10.0.0.3&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; SRV01.localdomain&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {21, 80, 139, 445...} &amp;nbsp;&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;10.0.0.10&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;SP01.localdomain&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;{80, 139, 445}&amp;nbsp;&lt;/p&gt;
&lt;p&gt;There are, of course, other tools that you can use when performing network scans. One such tool is the &lt;b&gt;Nmap&lt;/b&gt; security scanner, which has the possibility to perform the tasks described previously and a lot more. &amp;nbsp;As I mentioned earlier, Windows PowerShell has full support for executables, so another approach for performing a network scan would be to invoke nmap.exe and parse the XML output into a Windows PowerShell custom object to utilize the benefits of Windows PowerShell when working with the ouput. The following example demonstrates how to run nmap.exe and output the results to an XML document.&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;PS &amp;gt; &amp;amp; &amp;#39;C:\Nmap\nmap.exe&amp;#39; -F 10.0.0.1/24 -oX C:\temp\nmap.xml&lt;/p&gt;
&lt;p&gt;Next, we can use &lt;b&gt;Get-Content&lt;/b&gt; and read the content of the XML document. By adding the &lt;b&gt;[xml]&lt;/b&gt; data type and placing the cmdlet within parenthesis, the content is read as an XML object.&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;PS &amp;gt; $nmap = [xml](Get-Content C:\temp\nmap.xml)&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;PS &amp;gt; $nmap.nmaprun.host&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;starttime : 1340110002&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;endtime &amp;nbsp;: 1340110018&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;status&amp;nbsp; : status&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;address &amp;nbsp;: {address, address}&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;hostnames :&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;ports&amp;nbsp; &amp;nbsp;: ports&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;times&amp;nbsp; &amp;nbsp;: times&lt;/p&gt;
&lt;h3&gt;Downloads&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;To download this entire code sample, see &lt;a href="http://gallery.technet.microsoft.com/scriptcenter/Invoke-TSPingSweep-b71f1b9b" target="_blank"&gt;Invoke-TSPingSweep&lt;/a&gt; in the Script Center Repository.&lt;/li&gt;
&lt;li&gt;Additional functions and code related to security are available on the &lt;a href="http://www.truesec.com/security/tools" target="_blank"&gt;TruSec&lt;/a&gt; website.&lt;/li&gt;
&lt;li&gt;For more information about Nmap, see the &lt;a href="http://nmap.org/" target="_blank"&gt;NMAP.ORG&lt;/a&gt; site.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;~Niklas&lt;/p&gt;
&lt;p&gt;I want to thank Niklas for an interesting and informative blog. Security Week will continue tomorrow with Part 2 of Niklas&amp;rsquo;s security series.&lt;/p&gt;
&lt;p&gt;I invite you to follow me on &lt;a href="http://bit.ly/scriptingguystwitter" target="_blank"&gt;Twitter&lt;/a&gt; and &lt;a href="http://bit.ly/scriptingguysfacebook" target="_blank"&gt;Facebook&lt;/a&gt;. If you have any questions, send email to me at &lt;a href="mailto:scripter@microsoft.com" target="_blank"&gt;scripter@microsoft.com&lt;/a&gt;, or post your questions on the &lt;a href="http://bit.ly/scriptingforum" target="_blank"&gt;Official Scripting Guys Forum&lt;/a&gt;. See you tomorrow. Until then, peace.&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Ed Wilson, Microsoft Scripting Guy&lt;/b&gt;&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.technet.com/aggbug.aspx?PostID=3506692" width="1" height="1" alt="" /&gt;</description></item><item><title>Hey, Scripting Guy! Weekend Scripter: Improving Yesterday’s Windows Firewall Script</title><link>http://powershell.com/cs/blogs/hey-scriptingguy/archive/2010/07/04/hey-scripting-guy-weekend-scripter-improving-yesterday-s-windows-firewall-script.aspx</link><pubDate>Sun, 04 Jul 2010 05:00:00 GMT</pubDate><guid isPermaLink="false">f421715f-7aba-45f0-8a8d-44de5318a3a7:7073</guid><dc:creator>Anonymous</dc:creator><description>Microsoft Scripting Guy Ed Wilson here. The Smokey Mountains are about 10 degrees cooler than Charlotte , North Carolina , is. The problem is that it was nearly 100 degrees Fahrenheit in Charlotte. Anyway, getting to spend some time with my old high school...(&lt;a href="http://blogs.technet.com/b/heyscriptingguy/archive/2010/07/04/hey-scripting-guy-weekend-scripter-improving-yesterday-s-windows-firewall-script.aspx"&gt;read more&lt;/a&gt;)&lt;img src="http://blogs.technet.com/aggbug.aspx?PostID=3340569" width="1" height="1" alt="" /&gt;</description></item><item><title>Hey, Scripting Guy! Weekend Scripter: How to Retrieve Enabled Windows Firewall Rules</title><link>http://powershell.com/cs/blogs/hey-scriptingguy/archive/2010/07/03/hey-scripting-guy-weekend-scripter-how-to-retrieve-enabled-windows-firewall-rules.aspx</link><pubDate>Sat, 03 Jul 2010 05:00:00 GMT</pubDate><guid isPermaLink="false">f421715f-7aba-45f0-8a8d-44de5318a3a7:7068</guid><dc:creator>Anonymous</dc:creator><description>Microsoft Scripting Guy Ed Wilson here. The Scripting Wife and I are getting ready to head up to the mountains in search of a bit of cool air. Even if it is hot up there, it will still be cool because we are meeting one of my old high school friends....(&lt;a href="http://blogs.technet.com/b/heyscriptingguy/archive/2010/07/03/hey-scripting-guy-weekend-scripter-how-to-retrieve-enabled-windows-firewall-rules.aspx"&gt;read more&lt;/a&gt;)&lt;img src="http://blogs.technet.com/aggbug.aspx?PostID=3340565" width="1" height="1" alt="" /&gt;</description></item></channel></rss>