<?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>Trends in Technology</title>
	<atom:link href="http://blog.robbiefoust.com/?feed=rss2" rel="self" type="application/rss+xml" />
	<link>http://blog.robbiefoust.com</link>
	<description>All about Powershell</description>
	<lastBuildDate>Wed, 08 Apr 2009 01:50:59 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Improving mouse response in VMware console</title>
		<link>http://blog.robbiefoust.com/?p=85</link>
		<comments>http://blog.robbiefoust.com/?p=85#comments</comments>
		<pubDate>Wed, 08 Apr 2009 01:50:59 +0000</pubDate>
		<dc:creator>rfoust</dc:creator>
				<category><![CDATA[Powershell]]></category>
		<category><![CDATA[Powershell v1]]></category>
		<category><![CDATA[VMware]]></category>

		<guid isPermaLink="false">http://blog.robbiefoust.com/?p=85</guid>
		<description><![CDATA[If you have a VMware ESX cluster running some Windows VMs, you&#8217;ve probably noticed very poor mouse response when on the console of your VMs.  The fix is actually very simple.  You need to bump up the hardware acceleration in the display preferences.  You can either do it from the GUI (right [...]]]></description>
			<content:encoded><![CDATA[<p>If you have a VMware ESX cluster running some Windows VMs, you&#8217;ve probably noticed very poor mouse response when on the console of your VMs.  The fix is actually very simple.  You need to bump up the hardware acceleration in the display preferences.  You can either do it from the GUI (right click desktop -> properties -> settings -> advanced -> troubleshoot), or you can do it from Powershell:</p>

<div class="wp_syntax"><div class="code"><pre class="powershell" style="font-family:monospace;"><span style="color: #008080; font-weight: bold;">set-itemproperty</span> <span style="color: #008080; font-style: italic;">-path</span> <span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span><span style="color: #008080; font-weight: bold;">get-itemproperty</span> <span style="color: #800000;">&quot;hklm:\hardware\devicemap\video&quot;</span><span style="color: #000000;">&#41;</span>.<span style="color: #800000;">&quot;\Device\Video0&quot;</span><span style="color: #000000;">&#41;</span> <span style="color: #FF0000;">-replace</span> <span style="color: #800000;">&quot;\\Registry\\Machine&quot;</span><span style="color: pink;">,</span><span style="color: #800000;">&quot;HKLM:&quot;</span><span style="color: #000000;">&#41;</span> <span style="color: #008080; font-style: italic;">-name</span> <span style="color: #800000;">&quot;Acceleration.Level&quot;</span> <span style="color: #008080; font-style: italic;">-value</span> <span style="color: #000000;">0</span></pre></div></div>

<p>What this command does is query the HKLM:\Hardware\Devicemap\Video registry branch to find the true location of your primary video device, and then sets the Acceleration.Level key to a value of 0.</p>
<p>The only problem with editing the registry setting directly is that Windows doesn&#8217;t automatically reload the display configuration, so the change doesn&#8217;t immediately take effect.  Although it is technically possible to do that from Powershell, it isn&#8217;t easy (requires p/invoke) and you&#8217;re probably better off just rebooting the VM. :)</p>



Share and Enjoy:


	<a rel="nofollow"  href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fblog.robbiefoust.com%2F%3Fp%3D85&amp;title=Improving%20mouse%20response%20in%20VMware%20console&amp;bodytext=If%20you%20have%20a%20VMware%20ESX%20cluster%20running%20some%20Windows%20VMs%2C%20you%27ve%20probably%20noticed%20very%20poor%20mouse%20response%20when%20on%20the%20console%20of%20your%20VMs.%20%20The%20fix%20is%20actually%20very%20simple.%20%20You%20need%20to%20bump%20up%20the%20hardware%20acceleration%20in%20the%20display%20preferences.%20" title="Digg"><img src="http://blog.robbiefoust.com/wp-content/plugins/sociable/images/digg.png" title="Digg" alt="Digg" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://technorati.com/faves?add=http%3A%2F%2Fblog.robbiefoust.com%2F%3Fp%3D85" title="Technorati"><img src="http://blog.robbiefoust.com/wp-content/plugins/sociable/images/technorati.png" title="Technorati" alt="Technorati" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://www.facebook.com/share.php?u=http%3A%2F%2Fblog.robbiefoust.com%2F%3Fp%3D85&amp;t=Improving%20mouse%20response%20in%20VMware%20console" title="Facebook"><img src="http://blog.robbiefoust.com/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://delicious.com/post?url=http%3A%2F%2Fblog.robbiefoust.com%2F%3Fp%3D85&amp;title=Improving%20mouse%20response%20in%20VMware%20console&amp;notes=If%20you%20have%20a%20VMware%20ESX%20cluster%20running%20some%20Windows%20VMs%2C%20you%27ve%20probably%20noticed%20very%20poor%20mouse%20response%20when%20on%20the%20console%20of%20your%20VMs.%20%20The%20fix%20is%20actually%20very%20simple.%20%20You%20need%20to%20bump%20up%20the%20hardware%20acceleration%20in%20the%20display%20preferences.%20" title="del.icio.us"><img src="http://blog.robbiefoust.com/wp-content/plugins/sociable/images/delicious.png" title="del.icio.us" alt="del.icio.us" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fblog.robbiefoust.com%2F%3Fp%3D85&amp;title=Improving%20mouse%20response%20in%20VMware%20console" title="StumbleUpon"><img src="http://blog.robbiefoust.com/wp-content/plugins/sociable/images/stumbleupon.png" title="StumbleUpon" alt="StumbleUpon" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://reddit.com/submit?url=http%3A%2F%2Fblog.robbiefoust.com%2F%3Fp%3D85&amp;title=Improving%20mouse%20response%20in%20VMware%20console" title="Reddit"><img src="http://blog.robbiefoust.com/wp-content/plugins/sociable/images/reddit.png" title="Reddit" alt="Reddit" class="sociable-hovers" /></a>


<br/><br/>]]></content:encoded>
			<wfw:commentRss>http://blog.robbiefoust.com/?feed=rss2&amp;p=85</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Finding the Firewall Status from Powershell</title>
		<link>http://blog.robbiefoust.com/?p=76</link>
		<comments>http://blog.robbiefoust.com/?p=76#comments</comments>
		<pubDate>Sun, 01 Feb 2009 00:27:53 +0000</pubDate>
		<dc:creator>rfoust</dc:creator>
				<category><![CDATA[Powershell]]></category>

		<guid isPermaLink="false">http://blog.robbiefoust.com/?p=76</guid>
		<description><![CDATA[Using Group Policy in Active Directory, you can force the Windows Firewall to be enabled across your servers or clients, but sometimes you might not want to do that.  After all, when troubleshooting a software communications problem, it&#8217;s really easy to rule out the firewall configuration as a possible problem if you can disable it [...]]]></description>
			<content:encoded><![CDATA[<p>Using Group Policy in Active Directory, you can force the Windows Firewall to be enabled across your servers or clients, but sometimes you might not want to do that.  After all, when troubleshooting a software communications problem, it&#8217;s really easy to rule out the firewall configuration as a possible problem if you can disable it for a few minutes while you troubleshoot.</p>
<p>The only problem with allowing that kind of flexibility is how do you know that you remembered to re-enable the firewall on those 30 servers you worked on last week?  Well, some quick googling will show that you can use WMI to query the HNet_ConnectionProperties class and look at the IsFirewalled property.  Except&#8230;.it&#8217;s always True!  Even if the firewall is disabled.  Apparently, this is because the ICS service is running so the property is a bit misleading.</p>
<p>So I did things the hard way.  I used <a title="Regmon" href="http://technet.microsoft.com/en-us/sysinternals/bb896652.aspx" target="_blank">Regmon</a> to find out what registry key was flipped on/off when I enabled/disabled the Windows Firewall, and wrote a quick Powershell function to query that setting and return True or False (as type [bool]).</p>

<div class="wp_syntax"><div class="code"><pre class="powershell" style="font-family:monospace;"><span style="color: #008000;"># returns true if windows firewall is enabled, false if it is disabled</span>
<span style="color: #0000FF;">filter</span> global:get<span style="color: pink;">-</span>firewallstatus <span style="color: #000000;">&#40;</span><span style="color: #000000;">&#91;</span><span style="color: #008080;">string</span><span style="color: #000000;">&#93;</span><span style="color: #800080;">$computer</span> <span style="color: pink;">=</span> <span style="color: #800080;">$env</span>:computername<span style="color: #000000;">&#41;</span>
	<span style="color: #000000;">&#123;</span>
	<span style="color: #0000FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #000080;">$_</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span> <span style="color: #800080;">$computer</span> <span style="color: pink;">=</span> <span style="color: #000080;">$_</span> <span style="color: #000000;">&#125;</span>
&nbsp;
	<span style="color: #800080;">$HKLM</span> <span style="color: pink;">=</span> <span style="color: #000000;">2147483650</span>
&nbsp;
	<span style="color: #800080;">$reg</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">get-wmiobject</span> <span style="color: #008080; font-style: italic;">-list</span> <span style="color: #008080; font-style: italic;">-namespace</span> root\default <span style="color: pink;">-</span>computer <span style="color: #800080;">$computer</span> <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">where-object</span> <span style="color: #000000;">&#123;</span> <span style="color: #000080;">$_</span>.name <span style="color: #FF0000;">-eq</span> <span style="color: #800000;">&quot;StdRegProv&quot;</span> <span style="color: #000000;">&#125;</span>
	<span style="color: #800080;">$firewallEnabled</span> <span style="color: pink;">=</span> <span style="color: #800080;">$reg</span>.GetDwordValue<span style="color: #000000;">&#40;</span><span style="color: #800080;">$HKLM</span><span style="color: pink;">,</span> <span style="color: #800000;">&quot;System\ControlSet001\Services\SharedAccess\Parameters\FirewallPolicy\DomainProfile&quot;</span><span style="color: pink;">,</span><span style="color: #800000;">&quot;EnableFirewall&quot;</span><span style="color: #000000;">&#41;</span>
&nbsp;
	<span style="color: #000000;">&#91;</span><span style="color: #008080;">bool</span><span style="color: #000000;">&#93;</span><span style="color: #000000;">&#40;</span><span style="color: #800080;">$firewallEnabled</span>.uValue<span style="color: #000000;">&#41;</span>
	<span style="color: #000000;">&#125;</span></pre></div></div>

<p>Update (Feb 1, 2009):</p>
<p>In the comments, <a title="Shay Levy" href="http://blogs.microsoft.co.il/blogs/ScriptFanatic/" target="_blank">Shay Levy</a> reminded me of an alternate method of querying the registry that doesn&#8217;t use WMI.  Here is the exact same script using the <a title="MSDN" href="http://msdn.microsoft.com/en-us/library/microsoft.win32.registrykey.aspx" target="_blank">[Microsoft.Win32.RegistryKey]</a> class.  Thanks Shay!</p>

<div class="wp_syntax"><div class="code"><pre class="powershell" style="font-family:monospace;"><span style="color: #0000FF;">filter</span> global:get<span style="color: pink;">-</span>firewallstatus2 <span style="color: #000000;">&#40;</span><span style="color: #000000;">&#91;</span><span style="color: #008080;">string</span><span style="color: #000000;">&#93;</span><span style="color: #800080;">$computer</span> <span style="color: pink;">=</span> <span style="color: #800080;">$env</span>:computername<span style="color: #000000;">&#41;</span>
	<span style="color: #000000;">&#123;</span>
	<span style="color: #0000FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #000080;">$_</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span> <span style="color: #800080;">$computer</span> <span style="color: pink;">=</span> <span style="color: #000080;">$_</span> <span style="color: #000000;">&#125;</span>
&nbsp;
	<span style="color: #800080;">$reg</span> <span style="color: pink;">=</span> <span style="color: #000000;">&#91;</span>Microsoft.Win32.RegistryKey<span style="color: #000000;">&#93;</span>::OpenRemoteBaseKey<span style="color: #000000;">&#40;</span><span style="color: #800000;">&quot;LocalMachine&quot;</span><span style="color: pink;">,</span><span style="color: #800080;">$computer</span><span style="color: #000000;">&#41;</span>
&nbsp;
	<span style="color: #800080;">$firewallEnabled</span> <span style="color: pink;">=</span> <span style="color: #800080;">$reg</span>.OpenSubKey<span style="color: #000000;">&#40;</span><span style="color: #800000;">&quot;System\ControlSet001\Services\SharedAccess\Parameters\FirewallPolicy\DomainProfile&quot;</span><span style="color: #000000;">&#41;</span>.GetValue<span style="color: #000000;">&#40;</span><span style="color: #800000;">&quot;EnableFirewall&quot;</span><span style="color: #000000;">&#41;</span>
&nbsp;
	<span style="color: #000000;">&#91;</span><span style="color: #008080;">bool</span><span style="color: #000000;">&#93;</span><span style="color: #800080;">$firewallEnabled</span>
	<span style="color: #000000;">&#125;</span></pre></div></div>




Share and Enjoy:


	<a rel="nofollow"  href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fblog.robbiefoust.com%2F%3Fp%3D76&amp;title=Finding%20the%20Firewall%20Status%20from%20Powershell&amp;bodytext=Using%20Group%20Policy%20in%20Active%20Directory%2C%20you%20can%20force%20the%20Windows%20Firewall%20to%20be%20enabled%20across%20your%20servers%20or%20clients%2C%20but%20sometimes%20you%20might%20not%20want%20to%20do%20that.%20%C2%A0After%20all%2C%20when%20troubleshooting%20a%20software%20communications%20problem%2C%20it%27s%20really%20eas" title="Digg"><img src="http://blog.robbiefoust.com/wp-content/plugins/sociable/images/digg.png" title="Digg" alt="Digg" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://technorati.com/faves?add=http%3A%2F%2Fblog.robbiefoust.com%2F%3Fp%3D76" title="Technorati"><img src="http://blog.robbiefoust.com/wp-content/plugins/sociable/images/technorati.png" title="Technorati" alt="Technorati" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://www.facebook.com/share.php?u=http%3A%2F%2Fblog.robbiefoust.com%2F%3Fp%3D76&amp;t=Finding%20the%20Firewall%20Status%20from%20Powershell" title="Facebook"><img src="http://blog.robbiefoust.com/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://delicious.com/post?url=http%3A%2F%2Fblog.robbiefoust.com%2F%3Fp%3D76&amp;title=Finding%20the%20Firewall%20Status%20from%20Powershell&amp;notes=Using%20Group%20Policy%20in%20Active%20Directory%2C%20you%20can%20force%20the%20Windows%20Firewall%20to%20be%20enabled%20across%20your%20servers%20or%20clients%2C%20but%20sometimes%20you%20might%20not%20want%20to%20do%20that.%20%C2%A0After%20all%2C%20when%20troubleshooting%20a%20software%20communications%20problem%2C%20it%27s%20really%20eas" title="del.icio.us"><img src="http://blog.robbiefoust.com/wp-content/plugins/sociable/images/delicious.png" title="del.icio.us" alt="del.icio.us" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fblog.robbiefoust.com%2F%3Fp%3D76&amp;title=Finding%20the%20Firewall%20Status%20from%20Powershell" title="StumbleUpon"><img src="http://blog.robbiefoust.com/wp-content/plugins/sociable/images/stumbleupon.png" title="StumbleUpon" alt="StumbleUpon" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://reddit.com/submit?url=http%3A%2F%2Fblog.robbiefoust.com%2F%3Fp%3D76&amp;title=Finding%20the%20Firewall%20Status%20from%20Powershell" title="Reddit"><img src="http://blog.robbiefoust.com/wp-content/plugins/sociable/images/reddit.png" title="Reddit" alt="Reddit" class="sociable-hovers" /></a>


<br/><br/>]]></content:encoded>
			<wfw:commentRss>http://blog.robbiefoust.com/?feed=rss2&amp;p=76</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Packet Sniffer For Powershell (updated)</title>
		<link>http://blog.robbiefoust.com/?p=68</link>
		<comments>http://blog.robbiefoust.com/?p=68#comments</comments>
		<pubDate>Wed, 31 Dec 2008 01:39:31 +0000</pubDate>
		<dc:creator>rfoust</dc:creator>
				<category><![CDATA[Powershell]]></category>
		<category><![CDATA[Powershell v1]]></category>
		<category><![CDATA[Packet Sniffer]]></category>

		<guid isPermaLink="false">http://blog.robbiefoust.com/?p=68</guid>
		<description><![CDATA[View/Download Get-Packet.ps1 Script
I&#8217;ve posted an updated version of my Get-Packet Powershell packet sniffer script.  It is still completely standalone (it doesn&#8217;t require any additional software to run).  New features include:

Added IP Version field
TCP flags are now stored in an array
New switch added to resolve IPs to hostnames
ESC key will cleanly exit the script
New switch added [...]]]></description>
			<content:encoded><![CDATA[<p><a title="View Get-Packet.ps1 Script" href="http://poshcode.org/764" target="_self">View</a>/<a title="Download Get-Packet.ps1 Script" href="http://poshcode.org/get/764" target="_self">Download</a> Get-Packet.ps1 Script</p>
<p>I&#8217;ve posted an updated version of my Get-Packet Powershell packet sniffer script.  It is still completely standalone (it doesn&#8217;t require any additional software to run).  New features include:</p>
<ul>
<li>Added IP Version field</li>
<li>TCP flags are now stored in an array</li>
<li>New switch added to resolve IPs to hostnames</li>
<li>ESC key will cleanly exit the script</li>
<li>New switch added to generate statistics</li>
</ul>
<p>.NET includes a method to resolve IPs to Hostnames in [System.Net.Dns]::GetHostByName(), but if the lookup fails, then there is a 5 second delay that forces the script to pause execution. I instead chose to scrape the output of nslookup since it returns much quicker.  To further decrease processing time, I cache the results in a hashtable so multiple calls to nslookup for the same host are not needed.</p>
<p>Using the -Statistics switch will cause the script to generate statistics after the ESC key is pressed to stop the trace.  Most of the statistics code was borrowed from Jeffery Hicks&#8217;s <a title="Analyze-Packet" href="http://blog.sapien.com/index.php/2008/08/14/analyze-packet-reloaded/" target="_blank">Analyze-Packet</a> script.  A few basic stats will be printed to the screen with write-host, but the bulk of the data will be stored in a global $stats variable that you can access after the script has exited.  This isn&#8217;t how features would normally be implemented in cmdlets (they would be separate cmdlets), but I figured it would be ok in a script, and I have found the integration to be pretty convenient.</p>
<p>I had looked at adding IPv6 support, but design limitations in Windows prevented me from being able to access the raw IPv6 header.  See my <a href="http://blog.robbiefoust.com/?p=52" target="_blank">earlier blog post</a> for more details.  I also looked at adding the ability to save the capture in <a href="http://wiki.wireshark.org/Development/LibpcapFileFormat" target="_blank">libpcap</a> format, but I&#8217;m not getting the raw IP frame, so the data wouldn&#8217;t be as complete as a capture done in something like <a href="http://www.wireshark.org/" target="_blank">Wireshark</a>.</p>
<p>Anyway, I hope you enjoy the new features!  Let me know in the comments if you would like to see any other features added.</p>
<ul>
<li><span style="color: #000080;">EDIT: If you&#8217;re on Vista, you might need to disable the firewall to see TCP packets.  Not sure why yet. :)</span></li>
<li><span style="color: #000080;">EDIT #2: Found out why.  Add powershell.exe as an allowed application. (duh) :)</span></li>
</ul>
<p>- Robbie</p>



Share and Enjoy:


	<a rel="nofollow"  href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fblog.robbiefoust.com%2F%3Fp%3D68&amp;title=Packet%20Sniffer%20For%20Powershell%20%28updated%29&amp;bodytext=View%2FDownload%20Get-Packet.ps1%20Script%0D%0A%0D%0AI%27ve%20posted%20an%20updated%20version%20of%20my%20Get-Packet%20Powershell%20packet%20sniffer%20script.%20%C2%A0It%20is%20still%20completely%20standalone%20%28it%20doesn%27t%20require%20any%20additional%20software%20to%20run%29.%20%C2%A0New%20features%20include%3A%0D%0A%0D%0A%09Added%20IP%20Ver" title="Digg"><img src="http://blog.robbiefoust.com/wp-content/plugins/sociable/images/digg.png" title="Digg" alt="Digg" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://technorati.com/faves?add=http%3A%2F%2Fblog.robbiefoust.com%2F%3Fp%3D68" title="Technorati"><img src="http://blog.robbiefoust.com/wp-content/plugins/sociable/images/technorati.png" title="Technorati" alt="Technorati" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://www.facebook.com/share.php?u=http%3A%2F%2Fblog.robbiefoust.com%2F%3Fp%3D68&amp;t=Packet%20Sniffer%20For%20Powershell%20%28updated%29" title="Facebook"><img src="http://blog.robbiefoust.com/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://delicious.com/post?url=http%3A%2F%2Fblog.robbiefoust.com%2F%3Fp%3D68&amp;title=Packet%20Sniffer%20For%20Powershell%20%28updated%29&amp;notes=View%2FDownload%20Get-Packet.ps1%20Script%0D%0A%0D%0AI%27ve%20posted%20an%20updated%20version%20of%20my%20Get-Packet%20Powershell%20packet%20sniffer%20script.%20%C2%A0It%20is%20still%20completely%20standalone%20%28it%20doesn%27t%20require%20any%20additional%20software%20to%20run%29.%20%C2%A0New%20features%20include%3A%0D%0A%0D%0A%09Added%20IP%20Ver" title="del.icio.us"><img src="http://blog.robbiefoust.com/wp-content/plugins/sociable/images/delicious.png" title="del.icio.us" alt="del.icio.us" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fblog.robbiefoust.com%2F%3Fp%3D68&amp;title=Packet%20Sniffer%20For%20Powershell%20%28updated%29" title="StumbleUpon"><img src="http://blog.robbiefoust.com/wp-content/plugins/sociable/images/stumbleupon.png" title="StumbleUpon" alt="StumbleUpon" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://reddit.com/submit?url=http%3A%2F%2Fblog.robbiefoust.com%2F%3Fp%3D68&amp;title=Packet%20Sniffer%20For%20Powershell%20%28updated%29" title="Reddit"><img src="http://blog.robbiefoust.com/wp-content/plugins/sociable/images/reddit.png" title="Reddit" alt="Reddit" class="sociable-hovers" /></a>


<br/><br/>]]></content:encoded>
			<wfw:commentRss>http://blog.robbiefoust.com/?feed=rss2&amp;p=68</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
		<item>
		<title>.NET/C#/Powershell RegEx Quick Reference</title>
		<link>http://blog.robbiefoust.com/?p=59</link>
		<comments>http://blog.robbiefoust.com/?p=59#comments</comments>
		<pubDate>Mon, 29 Dec 2008 12:30:04 +0000</pubDate>
		<dc:creator>rfoust</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://blog.robbiefoust.com/?p=59</guid>
		<description><![CDATA[View/Download get-regex.ps1 Script
When I write scripts, every now and then I need to use Regular Expressions.  RegEx&#8217;s are very powerful, but I don&#8217;t use them enough to have it all memorized.  So instead of searching for my quick reference book all the time, I just made a Powershell function to display all of the info [...]]]></description>
			<content:encoded><![CDATA[<p><a title="View get-regex.ps1" href="http://poshcode.org/759" target="_self">View</a>/<a title="Download get-regex.ps1" href="http://poshcode.org/get/759" target="_self">Download</a> get-regex.ps1 Script</p>
<p>When I write scripts, every now and then I need to use <a title="Regular Expressions" href="http://en.wikipedia.org/wiki/Regex" target="_blank">Regular Expressions</a>.  RegEx&#8217;s are very powerful, but I don&#8217;t use them enough to have it all memorized.  So instead of searching for my quick reference book all the time, I just made a Powershell function to display all of the info at the prompt.</p>
<p>Poweshell&#8217;s built in &#8220;get-help&#8221; includes some basic RegEx documentation, but it is lacking some detail, and I don&#8217;t want to have to read through all the &#8220;fluff&#8221; to get to what I want.</p>
<p>The output of the script looks like this:</p>

<div class="wp_syntax"><div class="code"><pre class="powershell" style="font-family:monospace;"><span style="color: #008080; font-weight: bold;">PS</span> C:\scripts<span style="color: pink;">&gt;</span> get<span style="color: pink;">-</span>regex <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">ft</span> <span style="color: pink;">-</span>auto
Sequence                    Meaning                                                                      Table
<span style="color: pink;">--------</span>                    <span style="color: pink;">-------</span>                                                                      <span style="color: pink;">-----</span>
\a                          Alert <span style="color: #000000;">&#40;</span>bell<span style="color: #000000;">&#41;</span><span style="color: pink;">,</span> x07.                                                           Character <span style="color: #008080; font-weight: bold;">r</span>...
\b                          Backspace<span style="color: pink;">,</span> x08<span style="color: pink;">,</span> supported only <span style="color: #0000FF;">in</span> character class.                           Character <span style="color: #008080; font-weight: bold;">r</span>...
\e                          ESC character<span style="color: pink;">,</span> x1B.                                                          Character <span style="color: #008080; font-weight: bold;">r</span>...
\n                          Newline<span style="color: pink;">,</span> x0A.                                                                Character <span style="color: #008080; font-weight: bold;">r</span>...
\<span style="color: #008080; font-weight: bold;">r</span>                          Carriage <span style="color: #0000FF;">return</span><span style="color: pink;">,</span> x0D.                                                        Character <span style="color: #008080; font-weight: bold;">r</span>...
\f                          Form feed<span style="color: pink;">,</span> x0C.                                                              Character <span style="color: #008080; font-weight: bold;">r</span>...
\t                          Horizontal tab<span style="color: pink;">,</span> x09.                                                         Character <span style="color: #008080; font-weight: bold;">r</span>...
\v                          Vertical tab<span style="color: pink;">,</span> x0B.                                                           Character <span style="color: #008080; font-weight: bold;">r</span>...
\0octal                     Character specified by a two<span style="color: pink;">-</span>digit octal code.                               Character <span style="color: #008080; font-weight: bold;">r</span>...
\xhex                       Character specified by a two<span style="color: pink;">-</span>digit hexadecimal code.                         Character <span style="color: #008080; font-weight: bold;">r</span>...
\uhex                       Character specified by a four<span style="color: pink;">-</span>digit hexadecimal code.                        Character <span style="color: #008080; font-weight: bold;">r</span>...
\cchar                      Named control character.                                                     Character <span style="color: #008080; font-weight: bold;">r</span>...
<span style="color: #000000;">&#91;</span>...<span style="color: #000000;">&#93;</span>                       A single character listed or contained within a listed range.                Character c...
<span style="color: #000000;">&#91;</span>^...<span style="color: #000000;">&#93;</span>                      A single character not listed and not contained within a listed range.       Character c...
.                           Any character<span style="color: pink;">,</span> except a line terminator <span style="color: #000000;">&#40;</span>unless single<span style="color: pink;">-</span>line mode<span style="color: pink;">,</span> s<span style="color: #000000;">&#41;</span>.        Character c...
\w                          Word character.                                                              Character c...
\W                          Non<span style="color: pink;">-</span>word character.                                                          Character c...
\d                          Digit.                                                                       Character c...
\D                          Non<span style="color: pink;">-</span>digit.                                                                   Character c...
\s                          Whitespace character.                                                        Character c...
\S                          Non<span style="color: pink;">-</span>whitespace character.                                                    Character c...
&nbsp;
<span style="color: #000000;">&#40;</span>etc...<span style="color: #000000;">&#41;</span></pre></div></div>

<p>Enjoy!</p>
<p>- Robbie</p>



Share and Enjoy:


	<a rel="nofollow"  href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fblog.robbiefoust.com%2F%3Fp%3D59&amp;title=.NET%2FC%23%2FPowershell%20RegEx%20Quick%20Reference&amp;bodytext=View%2FDownload%20get-regex.ps1%20Script%0D%0A%0D%0AWhen%20I%20write%20scripts%2C%20every%20now%20and%20then%20I%20need%20to%20use%20Regular%20Expressions.%20%C2%A0RegEx%27s%20are%20very%20powerful%2C%20but%20I%20don%27t%20use%20them%20enough%20to%20have%20it%20all%20memorized.%20%C2%A0So%20instead%20of%20searching%20for%20my%20quick%20reference%20book" title="Digg"><img src="http://blog.robbiefoust.com/wp-content/plugins/sociable/images/digg.png" title="Digg" alt="Digg" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://technorati.com/faves?add=http%3A%2F%2Fblog.robbiefoust.com%2F%3Fp%3D59" title="Technorati"><img src="http://blog.robbiefoust.com/wp-content/plugins/sociable/images/technorati.png" title="Technorati" alt="Technorati" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://www.facebook.com/share.php?u=http%3A%2F%2Fblog.robbiefoust.com%2F%3Fp%3D59&amp;t=.NET%2FC%23%2FPowershell%20RegEx%20Quick%20Reference" title="Facebook"><img src="http://blog.robbiefoust.com/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://delicious.com/post?url=http%3A%2F%2Fblog.robbiefoust.com%2F%3Fp%3D59&amp;title=.NET%2FC%23%2FPowershell%20RegEx%20Quick%20Reference&amp;notes=View%2FDownload%20get-regex.ps1%20Script%0D%0A%0D%0AWhen%20I%20write%20scripts%2C%20every%20now%20and%20then%20I%20need%20to%20use%20Regular%20Expressions.%20%C2%A0RegEx%27s%20are%20very%20powerful%2C%20but%20I%20don%27t%20use%20them%20enough%20to%20have%20it%20all%20memorized.%20%C2%A0So%20instead%20of%20searching%20for%20my%20quick%20reference%20book" title="del.icio.us"><img src="http://blog.robbiefoust.com/wp-content/plugins/sociable/images/delicious.png" title="del.icio.us" alt="del.icio.us" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fblog.robbiefoust.com%2F%3Fp%3D59&amp;title=.NET%2FC%23%2FPowershell%20RegEx%20Quick%20Reference" title="StumbleUpon"><img src="http://blog.robbiefoust.com/wp-content/plugins/sociable/images/stumbleupon.png" title="StumbleUpon" alt="StumbleUpon" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://reddit.com/submit?url=http%3A%2F%2Fblog.robbiefoust.com%2F%3Fp%3D59&amp;title=.NET%2FC%23%2FPowershell%20RegEx%20Quick%20Reference" title="Reddit"><img src="http://blog.robbiefoust.com/wp-content/plugins/sociable/images/reddit.png" title="Reddit" alt="Reddit" class="sociable-hovers" /></a>


<br/><br/>]]></content:encoded>
			<wfw:commentRss>http://blog.robbiefoust.com/?feed=rss2&amp;p=59</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Powershell IPv6 Packet Sniffer: FAIL :(</title>
		<link>http://blog.robbiefoust.com/?p=52</link>
		<comments>http://blog.robbiefoust.com/?p=52#comments</comments>
		<pubDate>Sun, 28 Dec 2008 21:45:52 +0000</pubDate>
		<dc:creator>rfoust</dc:creator>
				<category><![CDATA[Powershell]]></category>
		<category><![CDATA[Powershell v1]]></category>

		<guid isPermaLink="false">http://blog.robbiefoust.com/?p=52</guid>
		<description><![CDATA[ 





About a year ago, I wrote a Powershell packet sniffer script that worked pretty well.  I wanted to add IPv6 support to it, so I spent a good chunk of the last day learning the protocol and trying to figure out how to do it in Powershell/.NET.  Unfortunately, what I found out is [...]]]></description>
			<content:encoded><![CDATA[<p> </p>
<div class="mceTemp">
<dl class="wp-caption alignright" style="width: 98px;">
<dt class="wp-caption-dt"><a href="http://www.ipv6ready.org"><img class=" " src="http://www.ipv6ready.org/images/logo_ready_phase-2.gif" alt="IPv6 Ready Logo" width="88" height="112" /></a></dt>
</dl>
</div>
<p>About a year ago, I wrote a Powershell packet sniffer script that worked pretty well.  I wanted to add IPv6 support to it, so I spent a good chunk of the last day learning the protocol and trying to figure out how to do it in Powershell/.NET.  Unfortunately, what I found out is that it isn&#8217;t possible.</p>
<p> </p>
<p>I basically had everything working, except for some reason I wasn&#8217;t receiving any IPv6 headers &#8212; only the payload.  After lots of research (er..googling, and experimentation), I discovered that there is a design limitation in the Windows implementation of IPv6 that prevents incoming IPv6 headers from being passed to a raw socket.  I also tried to get outgoing headers, but that wouldn&#8217;t work for me either.  Without the header, it&#8217;s very difficult to figure out what protocol the payload is, so for now, I think I&#8217;m going to have to abandon this effort.</p>
<p>All is not lost though.  I&#8217;ve made some other improvements to the original packet capture script and will post the new version soon.</p>
<p>- Robbie</p>



Share and Enjoy:


	<a rel="nofollow"  href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fblog.robbiefoust.com%2F%3Fp%3D52&amp;title=Powershell%20IPv6%20Packet%20Sniffer%3A%20FAIL%20%3A%28&amp;bodytext=%C2%A0%0D%0A%0D%0AAbout%20a%20year%20ago%2C%20I%20wrote%20a%20Powershell%20packet%20sniffer%20script%20that%20worked%20pretty%20well.%20%20I%20wanted%20to%20add%20IPv6%20support%20to%20it%2C%20so%20I%20spent%20a%20good%20chunk%20of%20the%20last%20day%20learning%20the%20protocol%20and%20trying%20to%20figure%20out%20how%20to%20do%20it%20in%20Powershell%2F.NET.%20%20" title="Digg"><img src="http://blog.robbiefoust.com/wp-content/plugins/sociable/images/digg.png" title="Digg" alt="Digg" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://technorati.com/faves?add=http%3A%2F%2Fblog.robbiefoust.com%2F%3Fp%3D52" title="Technorati"><img src="http://blog.robbiefoust.com/wp-content/plugins/sociable/images/technorati.png" title="Technorati" alt="Technorati" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://www.facebook.com/share.php?u=http%3A%2F%2Fblog.robbiefoust.com%2F%3Fp%3D52&amp;t=Powershell%20IPv6%20Packet%20Sniffer%3A%20FAIL%20%3A%28" title="Facebook"><img src="http://blog.robbiefoust.com/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://delicious.com/post?url=http%3A%2F%2Fblog.robbiefoust.com%2F%3Fp%3D52&amp;title=Powershell%20IPv6%20Packet%20Sniffer%3A%20FAIL%20%3A%28&amp;notes=%C2%A0%0D%0A%0D%0AAbout%20a%20year%20ago%2C%20I%20wrote%20a%20Powershell%20packet%20sniffer%20script%20that%20worked%20pretty%20well.%20%20I%20wanted%20to%20add%20IPv6%20support%20to%20it%2C%20so%20I%20spent%20a%20good%20chunk%20of%20the%20last%20day%20learning%20the%20protocol%20and%20trying%20to%20figure%20out%20how%20to%20do%20it%20in%20Powershell%2F.NET.%20%20" title="del.icio.us"><img src="http://blog.robbiefoust.com/wp-content/plugins/sociable/images/delicious.png" title="del.icio.us" alt="del.icio.us" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fblog.robbiefoust.com%2F%3Fp%3D52&amp;title=Powershell%20IPv6%20Packet%20Sniffer%3A%20FAIL%20%3A%28" title="StumbleUpon"><img src="http://blog.robbiefoust.com/wp-content/plugins/sociable/images/stumbleupon.png" title="StumbleUpon" alt="StumbleUpon" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://reddit.com/submit?url=http%3A%2F%2Fblog.robbiefoust.com%2F%3Fp%3D52&amp;title=Powershell%20IPv6%20Packet%20Sniffer%3A%20FAIL%20%3A%28" title="Reddit"><img src="http://blog.robbiefoust.com/wp-content/plugins/sociable/images/reddit.png" title="Reddit" alt="Reddit" class="sociable-hovers" /></a>


<br/><br/>]]></content:encoded>
			<wfw:commentRss>http://blog.robbiefoust.com/?feed=rss2&amp;p=52</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Atlassian Jira Powershell Interface</title>
		<link>http://blog.robbiefoust.com/?p=30</link>
		<comments>http://blog.robbiefoust.com/?p=30#comments</comments>
		<pubDate>Sat, 27 Dec 2008 12:30:13 +0000</pubDate>
		<dc:creator>rfoust</dc:creator>
				<category><![CDATA[Powershell]]></category>
		<category><![CDATA[Powershell v1]]></category>

		<guid isPermaLink="false">http://blog.robbiefoust.com/?p=30</guid>
		<description><![CDATA[View/Download jiraFunctions.ps1 Script
Atlassian Jira is a web-based bug/issue tracking software, but lucky for us, they provide a WSDL interface so that we can access it from a Powershell command line.
This script is only successful because of the work of Lee Holmes&#8217; connect-wsdl function.  I&#8217;ve included it as part of this script for convenience.
First you will [...]]]></description>
			<content:encoded><![CDATA[<p><a title="View jiraFunctions.ps1 Script" href="http://poshcode.org/751" target="_self">View</a>/<a title="Download jiraFunctions.ps1 Script" href="http://poshcode.org/get/751" target="_self">Download</a> jiraFunctions.ps1 Script</p>
<p><a href="http://www.atlassian.com/software/jira/" target="_blank">Atlassian Jira</a> is a web-based bug/issue tracking software, but lucky for us, they provide a WSDL interface so that we can access it from a Powershell command line.</p>
<p>This script is only successful because of the work of <a href="http://www.leeholmes.com/blog/" target="_blank">Lee Holmes&#8217;</a> <a href="http://www.leeholmes.com/blog/CallingAWebserviceFromPowerShell.aspx">connect-wsdl</a> function.  I&#8217;ve included it as part of this script for convenience.</p>
<p>First you will need to edit the $jiraURL variable in the script so that it points to your Jira WSDL URL.  I usually initialize most of my functions (and some variables) globally to make things easier, so after you&#8217;ve made the necessary edit, just run it from a command line.  The script will prompt you for a login/password for Jira.</p>
<p style="padding-left: 30px;"><strong><em>Note:</em></strong> <em>Some functions are incomplete/untested, so be sure to test before using in a production environment!</em></p>
<p>Connect-Jira is the first function that is called, and it establishes an initial connection to the Jira webservice.  This is the function that uses Lee&#8217;s connect-webservice function (and I honestly don&#8217;t know enough C# to understand how it works).</p>

<div class="wp_syntax"><div class="code"><pre class="powershell" style="font-family:monospace;"><span style="color: #800080;">$global</span>:jira <span style="color: pink;">=</span> connect<span style="color: pink;">-</span>jira $jiraURL</pre></div></div>

<p>After the connection is established, you are authenticated to Jira securely using a login/password.  Thanks to <a href="http://www.jaykul.com/">Joel Bennett</a> for the clever bits of code to securely grab the password without storing it anywhere.  There is a session ID stored in the $jiraAuthID variable that is used to identify your session.  A valid $jiraAuthID must be passed to most functions for them to succeed.  If the ID has timed out, the function calls will fail.</p>

<div class="wp_syntax"><div class="code"><pre class="powershell" style="font-family:monospace;"><span style="color: #800080;">$BSTR</span> <span style="color: pink;">=</span> <span style="color: #000000;">&#91;</span>System.Runtime.InteropServices.marshal<span style="color: #000000;">&#93;</span>::SecureStringToBSTR<span style="color: #000000;">&#40;</span><span style="color: #800080;">$credential</span>.Password<span style="color: #000000;">&#41;</span>
<span style="color: #800080;">$global</span>:jiraAuthID <span style="color: pink;">=</span> <span style="color: #800080;">$jira</span>.login<span style="color: #000000;">&#40;</span><span style="color: #800080;">$credential</span>.UserName.TrimStart<span style="color: #000000;">&#40;</span><span style="color: #800000;">&quot;\&quot;</span><span style="color: #000000;">&#41;</span><span style="color: pink;">,</span><span style="color: #000000;">&#91;</span>System.Runtime.InteropServices.marshal<span style="color: #000000;">&#93;</span>::PtrToStringAuto<span style="color: #000000;">&#40;</span><span style="color: #800080;">$BSTR</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#91;</span>System.Runtime.InteropServices.Marshal<span style="color: #000000;">&#93;</span>::ZeroFreeBSTR<span style="color: #000000;">&#40;</span><span style="color: #800080;">$BSTR</span><span style="color: #000000;">&#41;</span>;</pre></div></div>

<p>At this point, you are dropped back to the Powershell prompt where you can call the many functions available to you.  For example:</p>

<div class="wp_syntax"><div class="code"><pre class="powershell" style="font-family:monospace;"><span style="color: #008080; font-weight: bold;">PS</span> C:\scripts\jira<span style="color: pink;">&gt;</span> get<span style="color: pink;">-</span>jiraserverinfo
&nbsp;
baseUrl     : https:<span style="color: pink;">//</span>server.yourdomain.com<span style="color: pink;">/</span>jira
buildDate   : <span style="color: #000000;">9</span><span style="color: pink;">/</span><span style="color: #000000;">13</span><span style="color: pink;">/</span><span style="color: #000000;">2006</span> <span style="color: #000000;">4</span>:00:00 AM
buildNumber : <span style="color: #000000;">161</span>
edition     : Enterprise
version     : 3.6.5</pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="powershell" style="font-family:monospace;"><span style="color: #008080; font-weight: bold;">PS</span> C:\scripts\jira<span style="color: pink;">&gt;</span> get<span style="color: pink;">-</span>jiraresolution
&nbsp;
description                   icon                          name                          id
<span style="color: pink;">-----------</span>                   <span style="color: pink;">----</span>                          <span style="color: pink;">----</span>                          <span style="color: pink;">--</span>
A fix <span style="color: #0000FF;">for</span> this issue is ch...                               Fixed                         <span style="color: #000000;">1</span>
The problem described is a...                               Won<span style="color: #800000;">'t Fix                     2
The problem is a duplicate...                               Duplicate                     3
The problem is not complet...                               Incomplete                    4
All attempts at reproducin...                               Cannot Reproduce              5
The bug report describes b...                               NOTABUG                       6
Issue type was a general q...                               Issue Closed                  7</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="powershell" style="font-family:monospace;"><span style="color: #008080; font-weight: bold;">PS</span> C:\scripts\jira<span style="color: pink;">&gt;</span> get<span style="color: pink;">-</span>jiraissue <span style="color: #800000;">&quot;WIN-113&quot;</span>
&nbsp;
affectsVersions   : <span style="color: #000000;">&#123;</span><span style="color: #000000;">&#125;</span>
assignee          : rfoust
attachmentNames   : <span style="color: #000000;">&#123;</span><span style="color: #000000;">&#125;</span>
components        : <span style="color: #000000;">&#123;</span><span style="color: #000000;">&#125;</span>
created           : <span style="color: #000000;">7</span><span style="color: pink;">/</span><span style="color: #000000;">11</span><span style="color: pink;">/</span><span style="color: #000000;">2008</span> <span style="color: #000000;">9</span>:<span style="color: #000000;">12</span>:<span style="color: #000000;">48</span> PM
customFieldValues : <span style="color: #000000;">&#123;</span><span style="color: #000000;">&#125;</span>
description       : Create an altiris job to push out this script<span style="color: pink;">/</span>command to all windows servers.  There<span style="color: #800000;">'s a bug in the
                     powershell installer so this doesn'</span>t get done.  When complete<span style="color: pink;">,</span> powershell will start up <span style="color: pink;">*</span>much<span style="color: pink;">*</span> fas
                    ter.  <span style="color: #0000FF;">In</span> fact<span style="color: pink;">,</span> thats almost an understatement. :<span style="color: #000000;">&#41;</span>
&nbsp;
                    <span style="color: #008080; font-weight: bold;">Set-Alias</span> ngen <span style="color: pink;">@</span><span style="color: #000000;">&#40;</span>
                    <span style="color: #008080; font-weight: bold;">dir</span> <span style="color: #000000;">&#40;</span><span style="color: #008080; font-weight: bold;">join-path</span> $<span style="color: #000000;">&#123;</span>env:\windir<span style="color: #000000;">&#125;</span> <span style="color: #800000;">&quot;Microsoft.NET\Framework&quot;</span><span style="color: #000000;">&#41;</span> ngen.exe <span style="color: #008080; font-style: italic;">-recurse</span> <span style="color: pink;">|</span>
                    <span style="color: #008080; font-weight: bold;">sort</span> <span style="color: #008080; font-style: italic;">-descending</span> lastwritetime
                    <span style="color: #000000;">&#41;</span><span style="color: #000000;">&#91;</span><span style="color: #000000;">0</span><span style="color: #000000;">&#93;</span>.fullName
                    <span style="color: #000000;">&#91;</span>appdomain<span style="color: #000000;">&#93;</span>::currentdomain.getassemblies<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: pink;">|</span> <span style="color: pink;">%</span><span style="color: #000000;">&#123;</span>ngen <span style="color: #000080;">$_</span>.location<span style="color: #000000;">&#125;</span>
&nbsp;
                    <span style="color: #0000FF;">For</span> more info<span style="color: pink;">,</span> see:  http:<span style="color: pink;">//</span>blogs.msdn.com<span style="color: pink;">/</span>powershell<span style="color: pink;">/</span>archive<span style="color: pink;">/</span><span style="color: #000000;">2007</span><span style="color: pink;">/</span><span style="color: #000000;">11</span><span style="color: pink;">/</span>08<span style="color: pink;">/</span>update<span style="color: pink;">-</span>gac<span style="color: pink;">-</span>ps1.aspx
duedate           :
environment       :
fixVersions       : <span style="color: #000000;">&#123;</span><span style="color: #000000;">&#125;</span>
key               : WIN<span style="color: pink;">-</span><span style="color: #000000;">113</span>
priority          : <span style="color: #000000;">4</span>
project           : WIN
reporter          : rfoust
resolution        :
status            : <span style="color: #000000;">1</span>
summary           : Update GAC on all servers to decrease powershell startup time
<span style="color: #008080; font-weight: bold;">type</span>              : <span style="color: #000000;">4</span>
updated           : <span style="color: #000000;">7</span><span style="color: pink;">/</span><span style="color: #000000;">23</span><span style="color: pink;">/</span><span style="color: #000000;">2008</span> <span style="color: #000000;">1</span>:<span style="color: #000000;">40</span>:<span style="color: #000000;">17</span> PM
votes             : <span style="color: #000000;">0</span>
id                : <span style="color: #000000;">20685</span></pre></div></div>

<p>Enjoy! :)</p>
<p>- Robbie</p>



Share and Enjoy:


	<a rel="nofollow"  href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fblog.robbiefoust.com%2F%3Fp%3D30&amp;title=Atlassian%20Jira%20Powershell%20Interface&amp;bodytext=View%2FDownload%20jiraFunctions.ps1%20Script%0D%0A%0D%0AAtlassian%20Jira%20is%20a%20web-based%20bug%2Fissue%20tracking%20software%2C%20but%20lucky%20for%20us%2C%20they%20provide%20a%20WSDL%20interface%20so%20that%20we%20can%20access%20it%20from%20a%20Powershell%20command%20line.%0D%0A%0D%0AThis%20script%20is%20only%20successful%20because%20of" title="Digg"><img src="http://blog.robbiefoust.com/wp-content/plugins/sociable/images/digg.png" title="Digg" alt="Digg" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://technorati.com/faves?add=http%3A%2F%2Fblog.robbiefoust.com%2F%3Fp%3D30" title="Technorati"><img src="http://blog.robbiefoust.com/wp-content/plugins/sociable/images/technorati.png" title="Technorati" alt="Technorati" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://www.facebook.com/share.php?u=http%3A%2F%2Fblog.robbiefoust.com%2F%3Fp%3D30&amp;t=Atlassian%20Jira%20Powershell%20Interface" title="Facebook"><img src="http://blog.robbiefoust.com/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://delicious.com/post?url=http%3A%2F%2Fblog.robbiefoust.com%2F%3Fp%3D30&amp;title=Atlassian%20Jira%20Powershell%20Interface&amp;notes=View%2FDownload%20jiraFunctions.ps1%20Script%0D%0A%0D%0AAtlassian%20Jira%20is%20a%20web-based%20bug%2Fissue%20tracking%20software%2C%20but%20lucky%20for%20us%2C%20they%20provide%20a%20WSDL%20interface%20so%20that%20we%20can%20access%20it%20from%20a%20Powershell%20command%20line.%0D%0A%0D%0AThis%20script%20is%20only%20successful%20because%20of" title="del.icio.us"><img src="http://blog.robbiefoust.com/wp-content/plugins/sociable/images/delicious.png" title="del.icio.us" alt="del.icio.us" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fblog.robbiefoust.com%2F%3Fp%3D30&amp;title=Atlassian%20Jira%20Powershell%20Interface" title="StumbleUpon"><img src="http://blog.robbiefoust.com/wp-content/plugins/sociable/images/stumbleupon.png" title="StumbleUpon" alt="StumbleUpon" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://reddit.com/submit?url=http%3A%2F%2Fblog.robbiefoust.com%2F%3Fp%3D30&amp;title=Atlassian%20Jira%20Powershell%20Interface" title="Reddit"><img src="http://blog.robbiefoust.com/wp-content/plugins/sociable/images/reddit.png" title="Reddit" alt="Reddit" class="sociable-hovers" /></a>


<br/><br/>]]></content:encoded>
			<wfw:commentRss>http://blog.robbiefoust.com/?feed=rss2&amp;p=30</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Retrieve Cisco Unity License Info With Powershell</title>
		<link>http://blog.robbiefoust.com/?p=18</link>
		<comments>http://blog.robbiefoust.com/?p=18#comments</comments>
		<pubDate>Fri, 26 Dec 2008 23:34:32 +0000</pubDate>
		<dc:creator>rfoust</dc:creator>
				<category><![CDATA[Cisco Unity]]></category>
		<category><![CDATA[Powershell v1]]></category>

		<guid isPermaLink="false">http://blog.robbiefoust.com/?p=18</guid>
		<description><![CDATA[





View/Download Get-UnityLicense.ps1 Script
Many large companies and universities use Cisco Unity for their voicemail system.  Cisco provides some sample vbscript code to programatically interface with Unity, but so far they haven&#8217;t provided any Powershell cmdlets.  This function connects via HTTP to a Unity server and returns license information as a PSCustomObject.
Note: This post refers to the [...]]]></description>
			<content:encoded><![CDATA[<p><a title="View Get-UnityLicense.ps1" href="http://poshcode.org/750"></p>
<div class="mceTemp">
<dl class="wp-caption alignright" style="width: 190px;">
<dt class="wp-caption-dt"><a href="http://www.cisco.com"><img title="Cisco Logo" src="http://upload.wikimedia.org/wikipedia/en/6/64/Cisco_logo.svg" alt="Cisco Logo" width="180" height="94" /></a></dt>
</dl>
</div>
<p>View</a>/<a title="Download Get-UnityLicense.ps1" href="http://poshcode.org/get/750" target="_self">Download</a> Get-UnityLicense.ps1 Script</p>
<p>Many large companies and universities use Cisco Unity for their voicemail system.  Cisco provides some sample vbscript code to programatically interface with Unity, but so far they haven&#8217;t provided any Powershell cmdlets.  This function connects via HTTP to a Unity server and returns license information as a PSCustomObject.</p>
<p style="padding-left: 30px;"><em><strong>Note:</strong> This post refers to the full Cisco Unity, not Unity Express.</em></p>
<p>Unity provides its current license information on an XML page available through IIS. Because Powershell is built on .NET, it has very good support for HTTP and XML so this was actually a very simple function to write.</p>
<p>First we have to download the web page by initializing a <em>System.Net.Webclient</em> object, and calling the <em>DownloadString</em> method with the URL that we want.</p>

<div class="wp_syntax"><div class="code"><pre class="powershell" style="font-family:monospace;"><span style="color: #800080;">$webContent</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">new-object</span> net.webclient
<span style="color: #800080;">$page</span> <span style="color: pink;">=</span> <span style="color: #800080;">$webContent</span>.DownloadString<span style="color: #000000;">&#40;</span><span style="color: #800000;">&quot;http://$server/avxml/effectivelicense.asp&quot;</span><span style="color: #000000;">&#41;</span></pre></div></div>

<p>The XML that is returned has some whitespace at the top of the page that needs to be stripped out.  We use a simple RegEx to strip it out so that .NET doesn&#8217;t complain about it.  Then, converting the page into an XML object is as simple as casting it with <em><strong>[xml]</strong></em>.</p>

<div class="wp_syntax"><div class="code"><pre class="powershell" style="font-family:monospace;"><span style="color: #800080;">$page</span> <span style="color: pink;">=</span> <span style="color: #800080;">$page</span> <span style="color: #FF0000;">-replace</span> <span style="color: #800000;">&quot;^.<span style="color: #008080; font-weight: bold;">`n</span>&quot;</span>
<span style="color: #800080;">$license</span> <span style="color: pink;">=</span> <span style="color: #000000;">&#91;</span><span style="color: #008080;">xml</span><span style="color: #000000;">&#93;</span>$page</pre></div></div>

<p>Finally, we just store the various XML elements in a PSCustomObject and let it pass to the pipeline.</p>

<div class="wp_syntax"><div class="code"><pre class="powershell" style="font-family:monospace;"><span style="color: #008080; font-weight: bold;">new-object</span> psobject <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">add-member</span> <span style="color: #008080; font-style: italic;">-memberType</span> NoteProperty <span style="color: #008080; font-style: italic;">-name</span> LicLanguagesMax <span style="color: #008080; font-style: italic;">-value</span> <span style="color: #800080;">$license</span>.AvXmlLicData.Licenses.LicLanguagesMax <span style="color: #008080; font-style: italic;">-passthru</span> <span style="color: pink;">|</span>
 <span style="color: #008080; font-weight: bold;">add-member</span> <span style="color: #008080; font-style: italic;">-memberType</span> NoteProperty <span style="color: #008080; font-style: italic;">-name</span> LicMaxMsgRecLenIsLicensed <span style="color: #008080; font-style: italic;">-value</span> <span style="color: #800080;">$license</span>.AvXmlLicData.Licenses.LicMaxMsgRecLenIsLicensed <span style="color: #008080; font-style: italic;">-passthru</span> <span style="color: pink;">|</span>
 <span style="color: #008080; font-weight: bold;">add-member</span> <span style="color: #008080; font-style: italic;">-memberType</span> NoteProperty <span style="color: #008080; font-style: italic;">-name</span> LicPoolingIsEnabled <span style="color: #008080; font-style: italic;">-value</span> <span style="color: #800080;">$license</span>.AvXmlLicData.Licenses.LicPoolingIsEnabled <span style="color: #008080; font-style: italic;">-passthru</span> <span style="color: pink;">|</span>
 <span style="color: #008080; font-weight: bold;">add-member</span> <span style="color: #008080; font-style: italic;">-memberType</span> NoteProperty <span style="color: #008080; font-style: italic;">-name</span> LicSubscribersMax <span style="color: #008080; font-style: italic;">-value</span> <span style="color: #800080;">$license</span>.AvXmlLicData.Licenses.LicSubscribersMax <span style="color: #008080; font-style: italic;">-passthru</span> <span style="color: pink;">|</span>
 <span style="color: #008080; font-weight: bold;">add-member</span> <span style="color: #008080; font-style: italic;">-memberType</span> NoteProperty <span style="color: #008080; font-style: italic;">-name</span> LicUMSubscribersMax <span style="color: #008080; font-style: italic;">-value</span> <span style="color: #800080;">$license</span>.AvXmlLicData.Licenses.LicUMSubscribersMax <span style="color: #008080; font-style: italic;">-passthru</span> <span style="color: pink;">|</span>
 <span style="color: #008080; font-weight: bold;">add-member</span> <span style="color: #008080; font-style: italic;">-memberType</span> NoteProperty <span style="color: #008080; font-style: italic;">-name</span> LicVMISubscribersMax <span style="color: #008080; font-style: italic;">-value</span> <span style="color: #800080;">$license</span>.AvXmlLicData.Licenses.LicVMISubscribersMax <span style="color: #008080; font-style: italic;">-passthru</span> <span style="color: pink;">|</span>
 <span style="color: #008080; font-weight: bold;">add-member</span> <span style="color: #008080; font-style: italic;">-memberType</span> NoteProperty <span style="color: #008080; font-style: italic;">-name</span> LicVoicePortsMax <span style="color: #008080; font-style: italic;">-value</span> <span style="color: #800080;">$license</span>.AvXmlLicData.Licenses.LicVoicePortsMax <span style="color: #008080; font-style: italic;">-passthru</span> <span style="color: pink;">|</span>
 <span style="color: #008080; font-weight: bold;">add-member</span> <span style="color: #008080; font-style: italic;">-memberType</span> NoteProperty <span style="color: #008080; font-style: italic;">-name</span> AvLicUtilizationSecondaryServer <span style="color: #008080; font-style: italic;">-value</span> <span style="color: #800080;">$license</span>.AvXmlLicData.Utilization.AvLicUtilizationSecondaryServer <span style="color: #008080; font-style: italic;">-passthru</span> <span style="color: pink;">|</span>
 <span style="color: #008080; font-weight: bold;">add-member</span> <span style="color: #008080; font-style: italic;">-memberType</span> NoteProperty <span style="color: #008080; font-style: italic;">-name</span> AvLicUtilizationSubscribers <span style="color: #008080; font-style: italic;">-value</span> <span style="color: #800080;">$license</span>.AvXmlLicData.Utilization.AvLicUtilizationSubscribers <span style="color: #008080; font-style: italic;">-passthru</span> <span style="color: pink;">|</span>
 <span style="color: #008080; font-weight: bold;">add-member</span> <span style="color: #008080; font-style: italic;">-memberType</span> NoteProperty <span style="color: #008080; font-style: italic;">-name</span> AvLicUtilizationVMISubscribers <span style="color: #008080; font-style: italic;">-value</span> <span style="color: #800080;">$license</span>.AvXmlLicData.Utilization.AvLicUtilizationVMISubscribers <span style="color: #008080; font-style: italic;">-passthru</span></pre></div></div>

<p>The sample output looks like this:</p>

<div class="wp_syntax"><div class="code"><pre class="powershell" style="font-family:monospace;">LicLanguagesMax                 : <span style="color: #000000;">2</span>
LicMaxMsgRecLenIsLicensed       : <span style="color: #000000;">1</span>
LicPoolingIsEnabled             : <span style="color: #000000;">1</span>
LicSubscribersMax               : <span style="color: #000000;">15500</span>
LicUMSubscribersMax             : <span style="color: #000000;">0</span>
LicVMISubscribersMax            : <span style="color: #000000;">0</span>
LicVoicePortsMax                : <span style="color: #000000;">96</span>
AvLicUtilizationSecondaryServer : <span style="color: #000000;">0</span>
AvLicUtilizationSubscribers     : <span style="color: #000000;">8190</span>
AvLicUtilizationVMISubscribers  : <span style="color: #000000;">0</span></pre></div></div>

<p>Enjoy! :)</p>
<p>- Robbie</p>



Share and Enjoy:


	<a rel="nofollow"  href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fblog.robbiefoust.com%2F%3Fp%3D18&amp;title=Retrieve%20Cisco%20Unity%20License%20Info%20With%20Powershell&amp;bodytext=%0D%0A%0D%0AView%2FDownload%C2%A0Get-UnityLicense.ps1%20Script%0D%0A%0D%0AMany%20large%20companies%20and%20universities%20use%20Cisco%20Unity%20for%20their%20voicemail%20system.%20%20Cisco%20provides%20some%20sample%20vbscript%20code%20to%20programatically%20interface%20with%20Unity%2C%20but%20so%20far%20they%20haven%27t%20provided%20an" title="Digg"><img src="http://blog.robbiefoust.com/wp-content/plugins/sociable/images/digg.png" title="Digg" alt="Digg" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://technorati.com/faves?add=http%3A%2F%2Fblog.robbiefoust.com%2F%3Fp%3D18" title="Technorati"><img src="http://blog.robbiefoust.com/wp-content/plugins/sociable/images/technorati.png" title="Technorati" alt="Technorati" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://www.facebook.com/share.php?u=http%3A%2F%2Fblog.robbiefoust.com%2F%3Fp%3D18&amp;t=Retrieve%20Cisco%20Unity%20License%20Info%20With%20Powershell" title="Facebook"><img src="http://blog.robbiefoust.com/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://delicious.com/post?url=http%3A%2F%2Fblog.robbiefoust.com%2F%3Fp%3D18&amp;title=Retrieve%20Cisco%20Unity%20License%20Info%20With%20Powershell&amp;notes=%0D%0A%0D%0AView%2FDownload%C2%A0Get-UnityLicense.ps1%20Script%0D%0A%0D%0AMany%20large%20companies%20and%20universities%20use%20Cisco%20Unity%20for%20their%20voicemail%20system.%20%20Cisco%20provides%20some%20sample%20vbscript%20code%20to%20programatically%20interface%20with%20Unity%2C%20but%20so%20far%20they%20haven%27t%20provided%20an" title="del.icio.us"><img src="http://blog.robbiefoust.com/wp-content/plugins/sociable/images/delicious.png" title="del.icio.us" alt="del.icio.us" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fblog.robbiefoust.com%2F%3Fp%3D18&amp;title=Retrieve%20Cisco%20Unity%20License%20Info%20With%20Powershell" title="StumbleUpon"><img src="http://blog.robbiefoust.com/wp-content/plugins/sociable/images/stumbleupon.png" title="StumbleUpon" alt="StumbleUpon" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://reddit.com/submit?url=http%3A%2F%2Fblog.robbiefoust.com%2F%3Fp%3D18&amp;title=Retrieve%20Cisco%20Unity%20License%20Info%20With%20Powershell" title="Reddit"><img src="http://blog.robbiefoust.com/wp-content/plugins/sociable/images/reddit.png" title="Reddit" alt="Reddit" class="sociable-hovers" /></a>


<br/><br/>]]></content:encoded>
			<wfw:commentRss>http://blog.robbiefoust.com/?feed=rss2&amp;p=18</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Powershell: IP Packet Sniffer Script</title>
		<link>http://blog.robbiefoust.com/?p=9</link>
		<comments>http://blog.robbiefoust.com/?p=9#comments</comments>
		<pubDate>Sat, 03 Nov 2007 02:51:00 +0000</pubDate>
		<dc:creator>rfoust</dc:creator>
				<category><![CDATA[Powershell]]></category>
		<category><![CDATA[Powershell v1]]></category>

		<guid isPermaLink="false">http://blog.robbiefoust.com/?p=9</guid>
		<description><![CDATA[I was looking for a Powershell script that would capture raw IP packets on the network and shove them into an object, but the only one I was able to find was a commercial cmdlet that was out of my budget.  So, I decided that I would attempt to write my own.  I [...]]]></description>
			<content:encoded><![CDATA[<p>I was looking for a Powershell script that would capture raw IP packets on the network and shove them into an object, but the only one I was able to find was a commercial cmdlet that was out of my budget.  So, I decided that I would attempt to write my own.  I figured it would be a great learning exercise (and it was), but I went into the project with the goal of avoiding any 3rd party software, to avoid compiling anything (like a cmdlet written in C#), and I didn&#8217;t want to install a driver shim.  In other words, I wanted a plain &#8216;ol script that could be run on any computer.</p>
<p>I basically spent a lot of time googling and I got a lot of help from the guys over in the #Powershell IRC channel (irc.freenode.net).  All of that combined with trial-and-error, I give you&#8230;. *drumroll*  <a href="http://www.duke.edu/~rfoust/scripts/get-packet.ps1">get-packet.ps1</a>.</p>
<p>The script recognizes IPv4 TCP, UDP, ICMP, and IGMP packets (for now).  The thing that took me the longest amount of time trying to figure out was how to get all packets that the network card was seeing on the wire, not just packets destined for my IP address and a particular port number.  The solution was hard to find but wasn&#8217;t terribly difficult to understand.</p>

<div class="wp_syntax"><div class="code"><pre class="powershell" style="font-family:monospace;"><span style="color: #008000;"># Create a new socket... SocketType should be Raw, and ProtocolType must be IP for promiscuous mode.</span>
<span style="color: #800080;">$socket</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">new-object</span> system.net.sockets.socket<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#91;</span>Net.Sockets.AddressFamily<span style="color: #000000;">&#93;</span>::InterNetwork<span style="color: pink;">,</span><span style="color: #000000;">&#91;</span>Net.Sockets.SocketType<span style="color: #000000;">&#93;</span>::Raw<span style="color: pink;">,</span><span style="color: #000000;">&#91;</span>Net.Sockets.ProtocolType<span style="color: #000000;">&#93;</span>::IP<span style="color: #000000;">&#41;</span>
&nbsp;
<span style="color: #008000;"># Include the IP header so we get the full packet</span>
<span style="color: #800080;">$socket</span>.setsocketoption<span style="color: #000000;">&#40;</span><span style="color: #800000;">&quot;IP&quot;</span><span style="color: pink;">,</span><span style="color: #800000;">&quot;HeaderIncluded&quot;</span><span style="color: pink;">,</span><span style="color: #800080;">$true</span><span style="color: #000000;">&#41;</span>
&nbsp;
<span style="color: #008000;"># bind to a local IP address$ipendpoint = new-object system.net.ipendpoint([net.ipaddress]&quot;$localIP&quot;,0)$socket.bind($ipendpoint)</span>
&nbsp;
<span style="color: #008000;"># this switches the NIC driver into promiscuous mode.  This requires admin rights.</span>
<span style="color: #000000;">&#91;</span>void<span style="color: #000000;">&#93;</span><span style="color: #800080;">$socket</span>.iocontrol<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#91;</span>net.sockets.iocontrolcode<span style="color: #000000;">&#93;</span>::ReceiveAll<span style="color: pink;">,</span><span style="color: #800080;">$byteIn</span><span style="color: pink;">,</span><span style="color: #800080;">$byteOut</span><span style="color: #000000;">&#41;</span></pre></div></div>

<p>I read somewhere that .net sockets really just uses winsock under the hood, so it really helped my understanding to read both the <a href="http://msdn2.microsoft.com/en-us/library/ms741621.aspx">winsock</a> and <a href="http://msdn2.microsoft.com/en-us/library/system.net.sockets.iocontrolcode.aspx">dotnet</a> documentation regarding sockets on msdn.  I won&#8217;t bother repeating what that documentation says here but if you&#8217;re trying to decypher this script and can&#8217;t quite figure it out, feel free to ask questions and I&#8217;ll try to explain.</p>
<p>Something else that I probably knew at one point but had since forgotten was that the byte order on the network wire is reversed.  On the wire it is &#8220;Big Endian&#8221; and on the PC it is &#8220;Little Endian.&#8221;  Wikipedia has a great explanation on <a href="http://en.wikipedia.org/wiki/Endianness">Endianness</a>.  Figuring out how to interpret the IP packets was the next biggest time suck and endianness was a large part of it.  Once I realized that <a href="http://msdn2.microsoft.com/en-us/library/system.net.ipaddress.networktohostorder.aspx">NetworkToHostOrder</a> didn&#8217;t support unsigned ints, I simply wrote a few functions to reverse the byte order (from &#8220;Network&#8221; to &#8220;Host&#8221;) and used <a href="http://msdn2.microsoft.com/en-us/library/system.bitconverter.aspx">BitConverter</a> to return the correct data type.</p>

<div class="wp_syntax"><div class="code"><pre class="powershell" style="font-family:monospace;"><span style="color: #008000;"># Takes a 2 byte array, switches it from big endian to little endian, and converts it to uint16.</span>
<span style="color: #0000FF;">function</span> NetworkToHostUInt16 <span style="color: #000000;">&#40;</span><span style="color: #800080;">$value</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span> <span style="color: #000000;">&#91;</span><span style="color: #008080;">Array</span><span style="color: #000000;">&#93;</span>::Reverse<span style="color: #000000;">&#40;</span><span style="color: #800080;">$value</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#91;</span>BitConverter<span style="color: #000000;">&#93;</span>::ToUInt16<span style="color: #000000;">&#40;</span><span style="color: #800080;">$value</span><span style="color: pink;">,</span><span style="color: #000000;">0</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #008000;"># Takes a 4 byte array, switches it from big endian to little endian, and converts it to uint32.</span>
<span style="color: #0000FF;">function</span> NetworkToHostUInt32 <span style="color: #000000;">&#40;</span><span style="color: #800080;">$value</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span> <span style="color: #000000;">&#91;</span><span style="color: #008080;">Array</span><span style="color: #000000;">&#93;</span>::Reverse<span style="color: #000000;">&#40;</span><span style="color: #800080;">$value</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#91;</span>BitConverter<span style="color: #000000;">&#93;</span>::ToUInt32<span style="color: #000000;">&#40;</span><span style="color: #800080;">$value</span><span style="color: pink;">,</span><span style="color: #000000;">0</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #008000;"># Takes a byte array, switches it from big endian to little endian, and converts it to a string.</span>
<span style="color: #0000FF;">function</span> ByteToString <span style="color: #000000;">&#40;</span><span style="color: #800080;">$value</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span> <span style="color: #800080;">$AsciiEncoding</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">new-object</span> system.text.asciiencoding <span style="color: #800080;">$AsciiEncoding</span>.GetString<span style="color: #000000;">&#40;</span><span style="color: #800080;">$value</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#125;</span></pre></div></div>

<p>After getting all the data out of the packets, I shove the ones I really want into a psobject.  When running the script, it will be visually more appealing if you pipe the output to format-table.</p>

<div class="wp_syntax"><div class="code"><pre class="powershell" style="font-family:monospace;"><span style="color: #008080; font-weight: bold;">PS</span> C:\<span style="color: pink;">&gt;</span> .<span style="color: pink;">/</span>get<span style="color: pink;">-</span>packet.ps1 <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">ft</span></pre></div></div>

<p>There are a lot more protocol types that I could be looking for, and I&#8217;ll probably add some of the more common ones eventually.  I&#8217;ve also looked into adding support to export and import the libpcap file format, but after looking at the libpcap source code, there&#8217;s a lot of ugly in there that I might just avoid for now.</p>
<p>If you find any bugs or have any ideas on optimizing the code, let me know!</p>
<p>Enjoy!</p>
<p>- Robbie</p>



Share and Enjoy:


	<a rel="nofollow"  href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fblog.robbiefoust.com%2F%3Fp%3D9&amp;title=Powershell%3A%20IP%20Packet%20Sniffer%20Script&amp;bodytext=I%20was%20looking%20for%20a%20Powershell%20script%20that%20would%20capture%20raw%20IP%20packets%20on%20the%20network%20and%20shove%20them%20into%20an%20object%2C%20but%20the%20only%20one%20I%20was%20able%20to%20find%20was%20a%20commercial%20cmdlet%20that%20was%20out%20of%20my%20budget.%20%20So%2C%20I%20decided%20that%20I%20would%20attempt%20to%20write%20" title="Digg"><img src="http://blog.robbiefoust.com/wp-content/plugins/sociable/images/digg.png" title="Digg" alt="Digg" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://technorati.com/faves?add=http%3A%2F%2Fblog.robbiefoust.com%2F%3Fp%3D9" title="Technorati"><img src="http://blog.robbiefoust.com/wp-content/plugins/sociable/images/technorati.png" title="Technorati" alt="Technorati" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://www.facebook.com/share.php?u=http%3A%2F%2Fblog.robbiefoust.com%2F%3Fp%3D9&amp;t=Powershell%3A%20IP%20Packet%20Sniffer%20Script" title="Facebook"><img src="http://blog.robbiefoust.com/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://delicious.com/post?url=http%3A%2F%2Fblog.robbiefoust.com%2F%3Fp%3D9&amp;title=Powershell%3A%20IP%20Packet%20Sniffer%20Script&amp;notes=I%20was%20looking%20for%20a%20Powershell%20script%20that%20would%20capture%20raw%20IP%20packets%20on%20the%20network%20and%20shove%20them%20into%20an%20object%2C%20but%20the%20only%20one%20I%20was%20able%20to%20find%20was%20a%20commercial%20cmdlet%20that%20was%20out%20of%20my%20budget.%20%20So%2C%20I%20decided%20that%20I%20would%20attempt%20to%20write%20" title="del.icio.us"><img src="http://blog.robbiefoust.com/wp-content/plugins/sociable/images/delicious.png" title="del.icio.us" alt="del.icio.us" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fblog.robbiefoust.com%2F%3Fp%3D9&amp;title=Powershell%3A%20IP%20Packet%20Sniffer%20Script" title="StumbleUpon"><img src="http://blog.robbiefoust.com/wp-content/plugins/sociable/images/stumbleupon.png" title="StumbleUpon" alt="StumbleUpon" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://reddit.com/submit?url=http%3A%2F%2Fblog.robbiefoust.com%2F%3Fp%3D9&amp;title=Powershell%3A%20IP%20Packet%20Sniffer%20Script" title="Reddit"><img src="http://blog.robbiefoust.com/wp-content/plugins/sociable/images/reddit.png" title="Reddit" alt="Reddit" class="sociable-hovers" /></a>


<br/><br/>]]></content:encoded>
			<wfw:commentRss>http://blog.robbiefoust.com/?feed=rss2&amp;p=9</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
	</channel>
</rss>
