<?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>Huddled Masses &#187; APIs</title>
	<atom:link href="http://huddledmasses.org/tag/apis/feed/" rel="self" type="application/rss+xml" />
	<link>http://huddledmasses.org</link>
	<description>You can do more than breathe for free...</description>
	<lastBuildDate>Fri, 27 Apr 2012 05:42:40 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
<cloud domain='huddledmasses.org' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
		<item>
		<title>How to: Invoke PowerShell and use the results from C#?</title>
		<link>http://huddledmasses.org/how-to-invoke-powershell-and-use-the-results-from-csharp/</link>
		<comments>http://huddledmasses.org/how-to-invoke-powershell-and-use-the-results-from-csharp/#comments</comments>
		<pubDate>Thu, 06 Jan 2011 06:51:07 +0000</pubDate>
		<dc:creator>Joel 'Jaykul' Bennett</dc:creator>
				<category><![CDATA[Huddled]]></category>
		<category><![CDATA[APIs]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[PoshConsole]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[PowerShell Host]]></category>
		<category><![CDATA[Sample Code]]></category>

		<guid isPermaLink="false">http://huddledmasses.org/?p=1603</guid>
		<description><![CDATA[One of the questions that comes up a lot about PowerShell lately is how to use it from C#. For the sake of a simple example, I figured it&#8217;s past time I post the sort-of &#8230; Hello World of PowerShell hosting. I&#8217;m going to present this app plus a little bit more at the next [...]]]></description>
			<content:encoded><![CDATA[	<p>One of the questions that comes up a lot about PowerShell lately is how to use it from C#.  For the sake of a simple example, I figured it&#8217;s past time I post the sort-of &#8230; Hello World of PowerShell hosting. I&#8217;m going to present this app plus a little bit more at the next <a href="http://PowerShellGroup.org/rochester.ny">Upstate NY PowerShell User Group</a>, so let&#8217;s go just a little deeper than a greeting. Let&#8217;s assume that you want to run a cmdlet or a script and get the output back to display it in your application. </p>

	<p>Of course, the simplest thing to do is just stick that stuff in a <a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.datagrid.aspx">DataGrid</a>, so we&#8217;ll just whip up a simple <span class="caps">WPF</span> window. Yes, <span class="caps">WPF</span> of course. I can&#8217;t go back to Windows Forms, even for just for a simple example like this, but it&#8217;s basically the same except you have to set the <a href="http://msdn.microsoft.com/en-us/library/system.windows.forms.datagrid.aspx&#39;s">DataGrid</a> DataSource property instead of the ItemsSource &#8230; anyway, here&#8217;s the XAML:</p>

	<div class="xml code xml" style="font-family:monospace;"><br />
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Window</span> <span style="color: #000066;">x:Class</span>=<span style="color: #ff0000;">&quot;WpfPowerShell.MainWindow&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">xmlns</span>=<span style="color: #ff0000;">&quot;http://schemas.microsoft.com/winfx/2006/xaml/presentation&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">xmlns:x</span>=<span style="color: #ff0000;">&quot;http://schemas.microsoft.com/winfx/2006/xaml&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">Height</span>=<span style="color: #ff0000;">&quot;300&quot;</span> <span style="color: #000066;">Width</span>=<span style="color: #ff0000;">&quot;700&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;DataGrid</span> <span style="color: #000066;">Name</span>=<span style="color: #ff0000;">&quot;dataGrid1&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Window<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp;</div>

	<p>Just add a reference to System.Management.Automation (it&#8217;s in the GAC: C:\Windows\assembly\GAC_MSIL\System.Management.Automation\1.0.0.0__31bf3856ad364e35\System.Management.Automation.dll) and then in your window&#8217;s constructor (or wherever you like), put this code:</p>

	<div class="csharp code csharp" style="font-family:monospace;"><br />
<span style="color: #008080; font-style: italic;">// Note: this takes a little while ...</span><br />
var ps <span style="color: #008000;">=</span> PowerShell.<span style="color: #0000FF;">Create</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span><br />
<br />
<span style="color: #008080; font-style: italic;">// Let's get all the processes:</span><br />
ps.<span style="color: #0000FF;">AddCommand</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;Get-Process&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span><br />
<br />
<span style="color: #008080; font-style: italic;">// Use the generic overload to cast the PSObjects to their base object:</span><br />
panel.<span style="color: #0000FF;">DataContext</span> <span style="color: #008000;">=</span> ps.<span style="color: #0000FF;">Invoke</span><span style="color: #008000;">&lt;</span>Process<span style="color: #008000;">&gt;</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp;</div>

	<p>That&#8217;s it. We&#8217;re done.</p>

	<h3>And now for something slightly more interesting</h3>

	<p>What about if we also wanted an easy way to spot the biggest memory consumers? We could start by sorting the processes by the WorkingSet, and pick just the 15 worst offenders. But let&#8217;s also add a chart to <em>visualize</em> just how bad those top offenders are. In <span class="caps">WPF</span>, this is simple: I&#8217;m going to use the free <a href="http://wpf.amcharts.com/">amCharts</a> in my example, but you can do the same thing with the free <a href="http://visifire.com/">visifire</a> or <a href="http://www.visiblox.com">visiblox</a> charts, or the (commercial only) <a href="http://www.telerik.com/products/wpf/chart.aspx">Telerik</a> <span class="caps">RAD</span> controls &#8230; etc. All of those work in both <span class="caps">WPF</span> and Silverlight (and all three of the &#8220;free&#8221; ones have commercial versions).</p>

	<div class="xml code xml" style="font-family:monospace;"><br />
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Window</span> <span style="color: #000066;">x:Class</span>=<span style="color: #ff0000;">&quot;WpfPowerShell.MainWindow&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">xmlns</span>=<span style="color: #ff0000;">&quot;http://schemas.microsoft.com/winfx/2006/xaml/presentation&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">xmlns:x</span>=<span style="color: #ff0000;">&quot;http://schemas.microsoft.com/winfx/2006/xaml&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">xmlns:am</span>=<span style="color: #ff0000;">&quot;http://schemas.amcharts.com/charts/wpf/2009/xaml&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">Title</span>=<span style="color: #ff0000;">&quot;PowerShell Demo&quot;</span> <span style="color: #000066;">Height</span>=<span style="color: #ff0000;">&quot;400&quot;</span> <span style="color: #000066;">Width</span>=<span style="color: #ff0000;">&quot;800&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Grid<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Grid.ColumnDefinitions<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;ColumnDefinition</span> <span style="color: #000066;">Width</span>=<span style="color: #ff0000;">&quot;3*&quot;</span> <span style="color: #000066;">MaxWidth</span>=<span style="color: #ff0000;">&quot;350&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;ColumnDefinition</span> <span style="color: #000066;">Width</span>=<span style="color: #ff0000;">&quot;4*&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Grid.ColumnDefinitions<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;am:PieChart</span> <span style="color: #000066;">Name</span>=<span style="color: #ff0000;">&quot;pieChart1&quot;</span> <span style="color: #000066;">ValueMemberPath</span>=<span style="color: #ff0000;">&quot;WorkingSet&quot;</span> <span style="color: #000066;">TitleMemberPath</span>=<span style="color: #ff0000;">&quot;ProcessName&quot;</span> <span style="color: #000066;">SlicesSource</span>=<span style="color: #ff0000;">&quot;{Binding}&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;DataGrid</span> <span style="color: #000066;">Grid.Column</span>=<span style="color: #ff0000;">&quot;1&quot;</span> <span style="color: #000066;">Name</span>=<span style="color: #ff0000;">&quot;dataGrid1&quot;</span> <span style="color: #000066;">ItemsSource</span>=<span style="color: #ff0000;">&quot;{Binding}&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Grid<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Window<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp;</div>

	<p>Of course, this got a little more complicated. We needed to put the controls in a panel of some sort (I chose to use a Grid mainly because it automatically causes the scroll viewer around the DataGrid, but that forces us to specify the ColumnDefinitions) and the PieChart needs bindings for the value and title of each slice. You&#8217;ll notice I set the ItemsSource of the DataGrid and the SlicesSource of the PieChart to &#8220;{Binding}&#8221; (side note: why can&#8217;t they just use &#8220;ItemsSource&#8221; like normal people?) ... </p>

	<p>Setting the sources to {Binding} causes them to just look at their data context, so now in the code behind, I can bind them <em>both at once</em> by just setting the DataContext of the window (try that in Windows Forms).</p>

	<div class="csharp code csharp" style="font-family:monospace;"><br />
<span style="color: #008080; font-style: italic;">// Note: this takes a little while ...</span><br />
var ps <span style="color: #008000;">=</span> PowerShell.<span style="color: #0000FF;">Create</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span><br />
<br />
<span style="color: #008080; font-style: italic;">// Get the 15 biggest memory users. Note that we're using AddScript now,</span><br />
<span style="color: #008080; font-style: italic;">// We should probably put this in a resource or a separate script file:</span><br />
ps.<span style="color: #0000FF;">AddScript</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;Get-Process | Sort WorkingSet | Select -Last 15&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span><br />
<br />
<span style="color: #008080; font-style: italic;">// Use the generic overload to cast the PSObjects to their base object, </span><br />
<span style="color: #008080; font-style: italic;">// Just set the DataContext of the window, the controls are data bound</span><br />
DataContext <span style="color: #008000;">=</span> ps.<span style="color: #0000FF;">Invoke</span><span style="color: #008000;">&lt;</span>Process<span style="color: #008000;">&gt;</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp;</div>

	<p>That&#8217;s all there is to it. I can attach my solution after I give my presentation if people want it, but there&#8217;s really nothing else in it (so far) except the references to the amCharts and System.Management.Automation &#8230;</p>]]></content:encoded>
			<wfw:commentRss>http://huddledmasses.org/how-to-invoke-powershell-and-use-the-results-from-csharp/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Windows PowerShell 2.0 SDK Released</title>
		<link>http://huddledmasses.org/windows-powershell-2-0-sdk-released/</link>
		<comments>http://huddledmasses.org/windows-powershell-2-0-sdk-released/#comments</comments>
		<pubDate>Wed, 23 Dec 2009 20:53:36 +0000</pubDate>
		<dc:creator>Joel 'Jaykul' Bennett</dc:creator>
				<category><![CDATA[Huddled]]></category>
		<category><![CDATA[APIs]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[SDK]]></category>

		<guid isPermaLink="false">http://huddledmasses.org/?p=1360</guid>
		<description><![CDATA[So, the Windows PowerShell 2.0 Software Development Kit is basically a collection of samples, and it has been released separately from the Windows Platform SDK for a change, making the download a tiny 2.35MB &#8230; There are lots of examples in there in C# (no other languages), and honestly, some of them ought to make [...]]]></description>
			<content:encoded><![CDATA[	<p>So, the <a href="http://support.microsoft.com/kb/968929">Windows PowerShell 2.0</a> <a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=50633A1F-A665-425D-923C-1A269F8AC084" title="SDK">Software Development Kit</a> is basically a collection of samples, and it has been released separately from the Windows Platform <span class="caps">SDK</span> for a change, making the download a tiny 2.35MB &#8230;</p>

	<p>There are lots of examples in there in C# (no other languages), and honestly, some of them ought to make it into <span class="caps">PSCX</span> or some other project where people could grab pre-compiled versions  <img src='http://huddledmasses.org/wordpress/wp-includes/' alt=';)' class='wp-smiley' /> </p>

	<p>	<ul>
		<li>A Template for creating PSProviders, and a sample PSProvider (for Access databases).</li>
		<li>A sample of participating in Transactions (a set of &#8220;transacted comment&#8221; cmdlets for creating comments that go along with a transaction).</li>
		<li>Example cmdlets: Select-Object, Select-String, Get-Process, Stop-Process</li>
		<li>Dealing with issues with Serialization in PowerShell
		<li>PowerShell Eventing:
	<ul>
		<li>Deriving from ObjectEventRegistrationBase to create Register-FileSystemEvent</li>
	</ul></li>
	<ul>
		<li>Receiving notifications from PowerShell Events on remote computers.</li>
		<li>Hosting APIs, including (among others):
		<li>Restricted runspaces</li>
		<li>Runspace pools</li>
		<li>Remote runspaces (and remote runspace pools)</li>
		<li>Running commands in parallel or sequentially</li>
		<li>Calling Cmdlets and passing parameters</li>
	</ul></li>
	</ul>
	<ul>
		<li>Reproducing the default PowerShell.exe output</li>
	</ul></li></p>

	<p>Honestly, if you&#8217;re a developer that&#8217;s been wondering about learning to code cmdlets, or host PowerShell as a scripting engine, now&#8217;s the time.</p>]]></content:encoded>
			<wfw:commentRss>http://huddledmasses.org/windows-powershell-2-0-sdk-released/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using REST API&#8217;s from PowerShell with the Dream SDK</title>
		<link>http://huddledmasses.org/using-rest-apis-from-powershell-with-the-dream-sdk/</link>
		<comments>http://huddledmasses.org/using-rest-apis-from-powershell-with-the-dream-sdk/#comments</comments>
		<pubDate>Sun, 30 Nov 2008 22:56:52 +0000</pubDate>
		<dc:creator>Joel 'Jaykul' Bennett</dc:creator>
				<category><![CDATA[Huddled]]></category>
		<category><![CDATA[APIs]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Get-Web]]></category>
		<category><![CDATA[Http]]></category>
		<category><![CDATA[HttpRest]]></category>
		<category><![CDATA[HttpWebRequest]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[REST]]></category>
		<category><![CDATA[Scripting]]></category>
		<category><![CDATA[wGet]]></category>

		<guid isPermaLink="false">http://huddledmasses.org/?p=838</guid>
		<description><![CDATA[Awhile back I wrote a Get-Web script, which I later converted to a compiled Get-Web cmdlet and module (pssnapin) ... adding support for POST forms. At the time, it seemed like GET and POST with some string variables pretty much covered what I&#8217;d ever want to do with web pages, however I found a few [...]]]></description>
			<content:encoded><![CDATA[	<p>Awhile back I wrote a <a href="wget-2-for-powershell">Get-Web script</a>, which I later converted to a compiled <a href="get-web-another-round-of-wget-for-powershell">Get-Web cmdlet</a> and module (pssnapin) ... adding support for <span class="caps">POST</span> forms.  At the time, it seemed like <span class="caps">GET</span> and <span class="caps">POST</span> with some string variables pretty much covered what I&#8217;d ever want to do with web pages, however I found a few places where I needed to <span class="caps">POST</span> a file attachment, and then a couple of full-on <span class="caps">REST</span> APIs, which use not just <span class="caps">GET</span> and <span class="caps">POST</span>, but <span class="caps">PUT</span> and <span class="caps">DELETE</span> as well. </p>

	<p>While I was playing with <a href="http://huddledmasses.org/of-dekiwiki-and-powershell-a-script-module/">scripting the <span class="caps">REST</span> <span class="caps">API</span> for DekiWiki</a> &#8230; I experimented with the <a href="http://wiki.developer.mindtouch.com/Dream">MindTouch Dream SDK</a> &#8230; and as a result, I&#8217;ve refactored the part of that module that actually does the <span class="caps">HTTP</span> work out into a little PowerShell 1.0 compatible script library. Of course, it depends on several dll&#8217;s (mindtouch.core.dll, mindtouch.dream.dll, and SgmlReaderDll.dll and log4net.dll) from the Dream <span class="caps">SDK</span>, which you can <a href="http://sourceforge.net/project/showfiles.php?group_id=173074">download from SourceForge</a> (ok, they&#8217;ve made the Dream <span class="caps">SDK</span> stuff hard to find, so here&#8217;s a temporary link to <a href="http://huddledmasses.org/downloads/HttpRest.7z">my module</a> with the DLLs in it).</p>

	<h2>Example Uses</h2>

	<div class="posh code posh" style="font-family:monospace;"><br />
<span style="color: #666666; font-style: italic;">## Retrieve Google search results:</span><br />
<span style="color: #666699; font-weight: bold;">function</span> <span style="color: #0066cc; font-style: italic;">Get-<span style="font-style: normal;">Google</span></span> <span style="color: #333;">&#123;</span><br />
&nbsp; <span style="color: #0066cc; font-style: italic;">Invoke-<span style="font-style: normal;">Http</span></span> GET http:<span style="color: #66cc66;">//</span>www.<span style="color: #003366;">google</span>.<span style="color: #003366;">com</span><span style="color: #66cc66;">/</span>search @<span style="color: #333;">&#123;</span>q<span style="color: #66cc66;">=</span><span style="color: #660033; font-weight: bold;">$args</span><span style="color: #333;">&#125;</span> <span style="color: #66cc66;">|</span> <br />
&nbsp; &nbsp; <span style="color: #0066cc; font-style: italic;">Receive-<span style="font-style: normal;">Http</span></span> <span style="color: #003366; font-weight: bold;">Xml</span> <span style="color: #009900;">&quot;//h3[@class='r']/a&quot;</span> <span style="color: #66cc66;">|</span> <span style="color: #660033;">Select</span> href, InnerText <br />
<span style="color: #333;">&#125;</span><br />
<br />
<span style="color: #666666; font-style: italic;">## Download a file from a web page</span><br />
<span style="color: #666699; font-weight: bold;">function</span> <span style="color: #0066cc; font-style: italic;">Get-<span style="font-style: normal;">WebFile</span></span><span style="color: #333;">&#40;</span><span style="color: #660033; font-weight: bold;">$url</span>,<span style="color: #660033; font-weight: bold;">$cred</span><span style="color: #333;">&#41;</span> <span style="color: #333;">&#123;</span><br />
&nbsp; <span style="color: #0066cc; font-style: italic;">Invoke-<span style="font-style: normal;">Http</span></span> GET <span style="color: #660033; font-weight: bold;">$url</span> <span style="color: #000066;">-auth</span> <span style="color: #660033; font-weight: bold;">$cred</span> <span style="color: #66cc66;">|</span> <span style="color: #0066cc; font-style: italic;">Receive-<span style="font-style: normal;">Http</span></span> File &nbsp;<br />
<span style="color: #333;">&#125;</span><br />
<br />
<span style="color: #666666; font-style: italic;">## Upload a PowerShell script to PasteBin</span><br />
<span style="color: #666699; font-weight: bold;">function</span> <span style="color: #0066cc; font-style: italic;">Send-<span style="font-style: normal;">Paste</span></span> <span style="color: #333;">&#123;</span><br />
<span style="color: #666699; font-weight: bold;">PARAM</span><span style="color: #333;">&#40;</span><span style="color: #660033; font-weight: bold;">$PastebinURI</span><span style="color: #66cc66;">=</span><span style="color: #009900;">&quot;http://posh.jaykul.com/p/&quot;</span>,<span style="color: #003366; font-weight: bold;"><span style="color: #333;">&#91;</span>IO.<span style="color: #003366;">FileInfo</span><span style="color: #333;">&#93;</span></span><span style="color: #660033; font-weight: bold;">$file</span><span style="color: #333;">&#41;</span><br />
<span style="color: #666699; font-weight: bold;">PROCESS</span> <span style="color: #333;">&#123;</span><br />
&nbsp; <span style="color: #666699; font-weight: bold;">if</span><span style="color: #333;">&#40;</span><span style="color: #660033; font-weight: bold;">$_</span><span style="color: #333;">&#41;</span><span style="color: #333;">&#123;</span><span style="color: #003366; font-weight: bold;"><span style="color: #333;">&#91;</span>IO.<span style="color: #003366;">FileInfo</span><span style="color: #333;">&#93;</span></span><span style="color: #660033; font-weight: bold;">$file</span><span style="color: #66cc66;">=</span><span style="color: #660033; font-weight: bold;">$_</span><span style="color: #333;">&#125;</span><br />
<br />
&nbsp; <span style="color: #666699; font-weight: bold;">if</span><span style="color: #333;">&#40;</span><span style="color: #660033; font-weight: bold;">$file</span>.<span style="color: #003366;">Exists</span><span style="color: #333;">&#41;</span> <span style="color: #333;">&#123;</span> <br />
&nbsp; &nbsp; <span style="color: #660033; font-weight: bold;">$ofs</span><span style="color: #66cc66;">=</span><span style="color: #009900;">&quot;<span style="color: #000099; font-weight: bold;">`n</span>&quot;</span><br />
&nbsp; &nbsp; <span style="color: #660033; font-weight: bold;">$result</span> <span style="color: #66cc66;">=</span> <span style="color: #0066cc; font-style: italic;">Invoke-<span style="font-style: normal;">Http</span></span> POST <span style="color: #660033; font-weight: bold;">$PastebinURI</span> @<span style="color: #333;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; format<span style="color: #66cc66;">=</span><span style="color: #009900;">&quot;posh&quot;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;"># PowerShell</span><br />
&nbsp; &nbsp; &nbsp; expiry<span style="color: #66cc66;">=</span><span style="color: #009900;">&quot;d&quot;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #666666; font-style: italic;"># (d)ay or (m)onth or (f)orever</span><br />
&nbsp; &nbsp; &nbsp; poster<span style="color: #66cc66;">=</span>$<span style="color: #333;">&#40;</span><span style="color: #003366; font-weight: bold;"><span style="color: #333;">&#91;</span>Security.<span style="color: #003366;">Principal</span>.<span style="color: #003366;">WindowsIdentity</span><span style="color: #333;">&#93;</span></span>::<span style="color: #003366;">GetCurrent</span><span style="color: #333;">&#40;</span><span style="color: #333;">&#41;</span>.<span style="color: #003366;">Name</span>.<span style="color: #333399; font-weight: bold; font-style: italic;">Split</span><span style="color: #333;">&#40;</span><span style="color: #009900;">&quot;\&quot;</span><span style="color: #333;">&#41;</span><span style="color: #333;">&#91;</span><span style="color: #66cc66;">-</span><span style="color: #cc66cc;">1</span><span style="color: #333;">&#93;</span><span style="color: #333;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; code2<span style="color: #66cc66;">=</span><span style="color: #009900;">&quot;$((gc $file) -replace &quot;</span>http:<span style="color: #66cc66;">//</span><span style="color: #009900;">&quot;,&quot;</span>http``:<span style="color: #66cc66;">//</span><span style="color: #009900;">&quot;)&quot;</span> <span style="color: #666666; font-style: italic;"># To get past the spam filter.</span><br />
&nbsp; &nbsp; &nbsp; paste<span style="color: #66cc66;">=</span><span style="color: #009900;">&quot;Send&quot;</span><br />
&nbsp; &nbsp; <span style="color: #333;">&#125;</span> <span style="color: #000066;">-Type</span> FORM_URLENCODED <span style="color: #000066;">-Wait</span><br />
&nbsp; &nbsp; <span style="color: #660033; font-weight: bold;">$xml</span> <span style="color: #66cc66;">=</span> <span style="color: #660033; font-weight: bold;">$result</span>.<span style="color: #003366;">AsDocument</span><span style="color: #333;">&#40;</span><span style="color: #333;">&#41;</span>.<span style="color: #003366;">ToXml</span><span style="color: #333;">&#40;</span><span style="color: #333;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #0066cc; font-style: italic;">write-<span style="font-style: normal;">output</span></span> <span style="color: #660033; font-weight: bold;">$xml</span>.<span style="color: #003366;">SelectSingleNode</span><span style="color: #333;">&#40;</span><span style="color: #009900;">&quot;//*[@class='highlight']/*&quot;</span><span style="color: #333;">&#41;</span>.<span style="color: #003366;">href</span><br />
&nbsp; <span style="color: #333;">&#125;</span> <span style="color: #666699; font-weight: bold;">else</span> <span style="color: #333;">&#123;</span> <span style="color: #666699; font-weight: bold;">throw</span> <span style="color: #009900;">&quot;File Not Found&quot;</span> <span style="color: #333;">&#125;</span><br />
<span style="color: #333;">&#125;</span><span style="color: #333;">&#125;</span><br />
<span style="color: #666666; font-style: italic;">#########################################################</span><br />
<br />
<span style="color: #666666; font-style: italic;">## Example, to download my PasswordRequired.dll:</span><br />
<span style="color: #660033; font-weight: bold;">$cred</span> <span style="color: #66cc66;">=</span> <span style="color: #0066cc; font-style: italic;">new-<span style="font-style: normal;">object</span></span> System.<span style="color: #003366;">Management</span>.<span style="color: #003366;">Automation</span>.<span style="color: #003366;">PSCredential</span> `<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #009900;">&quot;test&quot;</span>, $<span style="color: #333;">&#40;</span><span style="color: #0066cc; font-style: italic;">ConvertTo-<span style="font-style: normal;">SecureString</span></span> <span style="color: #009900;">&quot;password&quot;</span><span style="color: #333;">&#41;</span><br />
<span style="color: #0066cc; font-style: italic;">Get-<span style="font-style: normal;">WebFile</span></span> http:<span style="color: #66cc66;">//</span>huddledmasses.<span style="color: #003366;">org</span><span style="color: #66cc66;">/</span>downloads<span style="color: #66cc66;">/</span>PasswordRequired.<span style="color: #003366;">dll</span> <span style="color: #660033; font-weight: bold;">$cred</span><br />
<br />
<span style="color: #666666; font-style: italic;">## Example, to upload a script called TestScript.ps1 to the Pastebin we use on IRC:</span><br />
<span style="color: #660033;">ls</span> TestScript.<span style="color: #003366;">ps1</span> <span style="color: #66cc66;">|</span> <span style="color: #0066cc; font-style: italic;">Send-<span style="font-style: normal;">Paste</span></span> <span style="color: #009900;">&quot;http://posh.jaykul.com/p/&quot;</span><br />
<br />
&nbsp;</div>

	<p>There are basically two main functions: Invoke-Http and Receive-Http. There are also a few extra functions which are mostly just for use by these two functions, and then Set-HttpDefaultUrl and Set-HttpCredential which you can use to simplify your scripts. I intend to rewrite these as cmdlets in C# and contribute them to the <a href="http://CodePlex.com/PowerShellCX">PowerShell Community Extensions</a> along with some of my other networking cmdlets (Get-<span class="caps">DNS</span>), so if you have any suggestions, I&#8217;d love to hear them!</p>

	<h3>Invoke-Http</h3>

	<p>Invokes <span class="caps">HTTP</span> verbs (like <span class="caps">GET</span>, <span class="caps">POST</span>, <span class="caps">PUT</span>, and <span class="caps">DELETE</span>) against a <span class="caps">URL</span> with optional parameters (eg: name = value), input, etc &#8230; and returns the output as a MindTouch.Dream.Result<MindTouch.Dream.DreamMessage> or (optionally) as a MindTouch.Dream.DreamMessage &#8230;</p>

	<h4>Syntax</h4>

	<p><code>Invoke-Http</code>  <code>[-Verb] &#60;String&#62;</code>  <code>[[-Path] &#60;String&#62;]</code>  <code>[[-With] &#60;Hashtable&#62;]</code>  <code>[[-Content] &#60;Object&#62;]</code>  <code>[[-Type] &#60;String&#62;]</code>  <code>[[-Authenticate] &#60;String&#62;]</code>  <code>[-WaitForResponse]</code></p>

	<h4>Parameters</h4>

	<h5>Verb</h5>

	<p>The <span class="caps">HTTP</span> verb you want to invoke.  Defaults to <strong>GET</strong>, but can be anything your <span class="caps">HTTP</span> server supports.</p>

	<h5>Path</h5>

	<p>The <span class="caps">URL</span> you want to invoke against.  Can be a partial <span class="caps">URL</span>, if you first call <code>Set-HttpDefaultURL</code> first. You can also specify this as an array or a hashtable. This is particularly useful if you&#8217;re specifying a partial <span class="caps">URL</span>, and your <span class="caps">URL</span> is built based on logic in your code. If you pass an array, the values in the array are joined with forward-slashes. If you pass a hashtable, the keys and values are appended joined with forward-slashes, but the values are double encoded (by UrlEncode), ie: <code>$key/$(UrlEncode(UrlEncode($value))</code></p>

	<h5>With</h5>

	<p>The parameters to be passed with the verb call, as a hashtable. (these are particularly used for <span class="caps">POST</span>, etc). These are passed in the query as named parameters, with the values encoded.</p>

	<h5>Content</h5>

	<p>Anything you want to pass as content. In actuality, we really only handle three things: <span class="caps">XML</span> Documents, file paths (the file will be used as content), and everything else is passed as simple text.  If you need other data types, the &#8220;DreamMessage&#8221; that the scripts depend on can handle all sorts of data types, so you&#8217;ll just need to add it around line 50 of the script.</p>

	<h5>Type</h5>

	<p>This is the type of content.  We can automatically deduce this for <span class="caps">XML</span> or File objects, but if you want to force a type, you should use this parameter.  For instance, to fake a web form submission, you need to specify the type as <span class="caps">FORM</span> or FORM_URLENCODED but you can also specify the type as any of:  <span class="caps">ATOM</span>, <span class="caps">BINARY</span>, <span class="caps">BMP</span>, <span class="caps">CSS</span>, DREAM_EXCEPTION, FORM_URLENCODED, <span class="caps">GIF</span>, <span class="caps">HTML</span>, <span class="caps">HTTP</span>, <span class="caps">JPEG</span>, JS, <span class="caps">JSON</span>, MULTIPART_MIXED, <span class="caps">NOTHING</span> (mimetype -/-), <span class="caps">ANY</span> (mimetype */*), <span class="caps">PDF</span>, <span class="caps">PHP</span>, <span class="caps">PNG</span>, <span class="caps">RDF</span>, <span class="caps">RELAXNG</span>, <span class="caps">SVG</span>, ANY_TEXT (mimetype text/*), <span class="caps">TEXT</span> (mimetype text/plain, with the ISO-8859-1 encoding), TEXT_UTF8 (mimetype text/plain, with UTF8 encoding), TEXT_XML, <span class="caps">TIFF</span>, <span class="caps">VCAL</span>, <span class="caps">VERSIT</span>, <span class="caps">XHTML</span>, <span class="caps">XML</span>, <span class="caps">XRDS</span>.</p>

	<h5>Authenticate</h5>

	<p>You can pass either a boolean (in which case the HTTPRest scripts will use a default <code>$global:HttpRestCredential</code> which it will prompt for if you haven&#8217;t set it), or an actual PSCredential or NetworkCredential object.  In any case, this causes the invoke to contain network credentials. Note that sometimes you may need to pre-authenticate <strong>before</strong> making calls to a web-service.</p>

	<h5>WaitForResponse</h5>

	<p>A switch parameter that causes the query to wait until the response completes downloading, <strong>and return a DreamResponse</strong> instead of returning an incomplete <strong>Result<DreamResponse></strong> ...  this is useful when you know the response is a simple <span class="caps">XML</span> file and you need to parse it to determine whether your call has succeeded.  If you need to actually get the data out, or if you just need to know the method was invoked successfully, you shouldn&#8217;t pass this parameter.</p>

	<h3>Receive-Http</h3>

	<p>Receives the response or result from a Dream.Result or DreamMessage. as <span class="caps">XML</span>, XDoc, text, raw bytes, or even to file.  This function is really only useful to receive the output of Invoke-Http when you need the response content.</p>

	<h4>Syntax</h4>

	<p><code>Receive-Http</code>  <code>[[-Output] &#60;string:[Xml|File|Text|Bytes]&#62;]</code>  <code>[[-Path] &#60;string&#62;]</code>  <code>[[-InputObject] &#60;MindTouch.Dream.Result&#60;MindTouch.Dream.DreamMessage&#62;&#62;]</code> </p>

	<p><code>Receive-Http</code>  <code>[[-Output] &#60;string:[Xml|File|Text|Bytes]&#62;]</code>  <code>[[-Path] &#60;string&#62;]</code>  <code>[[-InputObject] &#60;MindTouch.Dream.DreamMessage&#62;]</code></p>

	<h4>Parameters</h4>

	<h5>Output</h5>

	<p>The <span class="caps">TYPE</span> of output you want: 
	<ul>
		<li><strong>Xml</strong> will return an XmlDocument &#8212; or XmlNode(s) if you pass a Path.</li>
		<li><strong>File</strong> will write to file &#8212; currently, you <strong>must</strong> pass a path, I didn&#8217;t make it guess it automatically.</li>
		<li><strong>Text</strong> will output text &#8212; in the case where the <strong>actual</strong> output is <span class="caps">XML</span>, this returns the InnerText.</li>
		<li><strong>Bytes</strong> returns an array of bytes&#8230;</li>
	</ul>
	<ul>
		<li><strong>XDoc</strong> returns a MindTouch.Dream.XDoc (not the .Net native class), which has a boatload of extra web-related methods and features you might find useful such as accepting XPath operators as indexers.</li>
	</ul></p>

	<h5>Path</h5>

	<p>A string containing the path for file output or XPath selector for <span class="caps">XML</span>, XDoc, and Text output</p>

	<h5>InputObject</h5>

	<p>The input <em>must</em> be either a <code>Result&#60;DreamMessage&#62;</code> or a <code>DreamMessage</code> itself.  Values passed on the pipeline are accepted into this parameter.</p>

	<h3>Set-HttpDefaultUrl</h3>

	<p>This takes the passed <span class="caps">URI</span> and sets it as the base (default) <span class="caps">URL</span> for the Invoke-Http function (if you set this, any path passed to Invoke-Http is treated as <em>relative</em> to this path).</p>

	<h3>Set-HttpCredential</h3>

	<p>This takes a <code>PSCredential</code> or <code>NetworkCredential</code> and stores it as a PSCredential for use by the Invoke-Http function. Particularly useful when you want to script a bunch of authenticated methods without being re-prompted. Note that if you don&#8217;t pass a credential, you&#8217;ll be prompted for one the usual way, so calling just <code>Set-HttpCredential</code> is sufficient when working on the command-line.</p>

	<h2>Miscellaneous</h2>

	<p>There are other functions in here, a few should be considered &#8220;internal&#8221; functions (when this is a module, they would not be exported: Get-DreamMessage, Get-DreamPlug, Get-HttpCredential) and a few of which came out of my utilities functions (like Encode-Twice, and Join-Url, Get-FileName, Get-UtcTime, and Get-CredentialBetter)...</p>

	<h2>Code (Updated 28 July 2010)</h2>

	<p><script type="text/javascript" src="http://PoshCode.org/embed/2028"></script></p>]]></content:encoded>
			<wfw:commentRss>http://huddledmasses.org/using-rest-apis-from-powershell-with-the-dream-sdk/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Of DekiWiki and PowerShell: A Script (Module)</title>
		<link>http://huddledmasses.org/of-dekiwiki-and-powershell-a-script-module/</link>
		<comments>http://huddledmasses.org/of-dekiwiki-and-powershell-a-script-module/#comments</comments>
		<pubDate>Fri, 14 Nov 2008 06:32:36 +0000</pubDate>
		<dc:creator>Joel 'Jaykul' Bennett</dc:creator>
				<category><![CDATA[Huddled]]></category>
		<category><![CDATA[APIs]]></category>
		<category><![CDATA[DekiWiki]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[REST]]></category>
		<category><![CDATA[Scripting]]></category>
		<category><![CDATA[Wiki]]></category>

		<guid isPermaLink="false">http://huddledmasses.org/?p=781</guid>
		<description><![CDATA[You may not have noticed, but there are several wiki&#8217;s with PowerShell content in them, but generally speaking, they are the results of the effort of a single person (or very a small group) ... and none of them seems to have captured the attention of the general PowerShell community. Certainly, the PowerShell Community site [...]]]></description>
			<content:encoded><![CDATA[	<p>You may not have noticed, but <a href="http://channel9.msdn.com/wiki/windowspowershellwiki/">there are</a> <a href="http://www.myitforum.com/myITWiki/Default.aspx?Page=winpowershell&#38;AspxAutoDetectCookieSupport=1">several wiki&#8217;s</a> with PowerShell content in them, but generally speaking, they are the results of the effort of a single person (or very a small group) ... and none of them seems to have captured the attention of the general PowerShell community.  Certainly, the <a href="http://PowerShellCommunity.org">PowerShell Community</a> site has never had it&#8217;s own wiki.</p>

	<p>I&#8217;ve been pushing for an unofficial community wiki for awhile, and recently, I had an opportunity to try out <a href="http://wiki.mindtouch.com">MindTouch DekiWiki</a> at work, and I was so impressed, I decided to <a href="http://wiki.poshcode.org/">throw one up</a> and take it upon myself to demo to <a href="http://halr9000.com/">Halr9000</a> and a few of the MVPs (and now &#8230; to all of you!) why I think we should set up a DekiWiki for our community  <img src='http://huddledmasses.org/wordpress/wp-includes/' alt=':)' class='wp-smiley' /> </p>

	<p>It&#8217;s really quite simple.  On top of having some really awesome features like hierarchical pages, a <span class="caps">WYSIWYG</span> editor, and built-in lucene search and file attachments &#8230; it also has a <span class="caps">REST</span> api, and you can edit the pages in plain-old <span class="caps">HTML</span> (not really surprising considering the <span class="caps">WYSIWYG</span> interface).  The combination of these two things, and the MindTouch <a href="http://wiki.developer.mindtouch.com/Dream">Dream</a> sdk (along with good examples of using it with the <a href="http://wiki.developer.mindtouch.com/MindTouch_Deki/API_Reference">Deki <span class="caps">REST</span> API</a>) make it so easy to work with in .Net and PowerShell, that I just felt compelled to share my scripts&#8230;</p>

	<p>First is the conversion script, which is based on <a href="http://blogs.vmware.com/vipowershell/2007/09/new-htmlhelp.html">New-HtmlHelp</a>, some excellent work by one of the VMWare PowerShell guys &#8230;</p>

	<p><script type="text/javascript" src="http://PoshCode.org/embed/670?height=200"></script></p>

	<p>But then, the more interesting stuff, written on top of <a href="http://wiki.developer.mindtouch.com/Dream">MindTouch Dream</a> (you need to <a href="http://sourceforge.net/project/showfiles.php?group_id=173074">download Dream from SourceForge.net</a> to use it, or just grab <a href="/downloads/DekiWiki.7z">both my scripts and the dlls in a 7-zip archive</a>), a series of cmdlets which abstract away some of the intricacies of the DekiWiki <span class="caps">API</span>. So far, I&#8217;ve only written a few &#8230; most notably: Set-DekiContent, which will allow you to write a little loop like this:</p>

	<div class="posh code posh" style="font-family:monospace;"><br />
<span style="color: #666699; font-weight: bold;">foreach</span><span style="color: #333;">&#40;</span><span style="color: #660033; font-weight: bold;">$cmd</span> <span style="color: #666699; font-weight: bold;">in</span> <span style="color: #333;">&#40;</span><span style="color: #660033;">gcm</span> <span style="color: #000066;">-type</span> cmdlet <span style="color: #66cc66;">|</span> ? <span style="color: #333;">&#123;</span> <span style="color: #660033; font-weight: bold;">$_</span>.<span style="color: #003366;">PsSnapin</span> <span style="color: #000066;">-like</span> <span style="color: #009900;">&quot;Microsoft.PowerShell*&quot;</span> <span style="color: #333;">&#125;</span><span style="color: #333;">&#41;</span><span style="color: #333;">&#41;</span> <span style="color: #333;">&#123;</span><br />
&nbsp; &nbsp;<span style="color: #0066cc; font-style: italic;">Get-<span style="font-style: normal;">Help</span></span> <span style="color: #660033; font-weight: bold;">$cmd</span>.<span style="color: #003366;">Name</span> <span style="color: #000066;">-full</span> <span style="color: #000066;">-EA</span> <span style="color: #009900;">&quot;SilentlyContinue&quot;</span> <span style="color: #66cc66;">|</span> <span style="color: #0066cc; font-style: italic;">ConvertTo-<span style="font-style: normal;">DekiContent</span></span> Cmdlet_Help <span style="color: #66cc66;">|</span> <br />
&nbsp; &nbsp;<span style="color: #66cc66;">%</span><span style="color: #333;">&#123;</span> <span style="color: #0066cc; font-style: italic;">Set-<span style="font-style: normal;">DekiContent</span></span> <span style="color: #009900;">&quot;Cmdlet_Help/$($cmd.PSSnapin)/$($cmd.Name)&quot;</span> <span style="color: #660033; font-weight: bold;">$_</span> <span style="color: #333;">&#125;</span><br />
<span style="color: #333;">&#125;</span></div>

	<p>Which produces this <a href="http://wiki.poshcode.org/Cmdlet_Documentation">PowerShell Cmdlet Help</a> &#8230; pretty cool, right?  Incidentally, feel free to contribute more, and/or comment on or edit the help for those cmdlets to improve upon it.</p>

	<p>Without futher ado, here&#8217;s the script module:</p>

	<p><script type="text/javascript" src="http://PoshCode.org/embed/671"></script></p>]]></content:encoded>
			<wfw:commentRss>http://huddledmasses.org/of-dekiwiki-and-powershell-a-script-module/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Google Charts from PowerShell &#8211; Part 1</title>
		<link>http://huddledmasses.org/google-charts-from-powershell-1/</link>
		<comments>http://huddledmasses.org/google-charts-from-powershell-1/#comments</comments>
		<pubDate>Thu, 28 Aug 2008 18:45:51 +0000</pubDate>
		<dc:creator>Joel 'Jaykul' Bennett</dc:creator>
				<category><![CDATA[Huddled]]></category>
		<category><![CDATA[APIs]]></category>
		<category><![CDATA[Charting]]></category>
		<category><![CDATA[Extended]]></category>
		<category><![CDATA[Google]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[Scripting]]></category>

		<guid isPermaLink="false">http://HuddledMasses.org/?p=647</guid>
		<description><![CDATA[Several people have blogged about using the Google charts api from PowerShell, but everyone seems to be using the &#8220;simple&#8221; numerical encoding, so I figured that as the first step of my own google chart api wrapper module I would start out by writing up a simple encoder. I&#8217;m not posting this to the script [...]]]></description>
			<content:encoded><![CDATA[	<p>Several people have blogged about using the Google charts api from PowerShell, but everyone seems to be using the &#8220;simple&#8221; numerical encoding, so I figured that as the first step of my own google chart api wrapper module I would start out by writing up a simple encoder.  I&#8217;m not posting this to the script repository until I&#8217;m done with it &#8212; this is just the number encoding function.  </p>

	<p>But I figured I&#8217;d blog it here in case it will help anyone else write the full wrapper module &#8220;for&#8221; me before I get around to it  <img src='http://huddledmasses.org/wordpress/wp-includes/' alt=':)' class='wp-smiley' />   In any case, remember this doesn&#8217;t encode numbers higher than 4095, so if you have a bunch of numbers and some of them might be larger than that, you&#8217;ll still need to normalize them so they are within that range.  I&#8217;ll post the function to normalize a series of numbers later this evening, because for some reason I can&#8217;t find it right now, but I&#8217;m sure I already wrote it  <img src='http://huddledmasses.org/wordpress/wp-includes/' alt=';)' class='wp-smiley' /> .</p>

	<div class="posh code posh" style="font-family:monospace;"><br />
<span style="color: #666666; font-style: italic;">## Google Chart API extended value encoding function</span><br />
<span style="color: #666666; font-style: italic;">#########################################################################</span><br />
<span style="color: #666699; font-weight: bold;">function</span> GoogleEncode <span style="color: #333;">&#123;</span><br />
<span style="color: #666699; font-weight: bold;">BEGIN</span> <span style="color: #333;">&#123;</span><br />
&nbsp; &nbsp;<span style="color: #666666; font-style: italic;">## Google's odydecody is a 64 character array</span><br />
&nbsp; &nbsp;<span style="color: #660033; font-weight: bold;">$ody</span> <span style="color: #66cc66;">=</span> <span style="color: #009900;">&quot;A&quot;</span>,<span style="color: #009900;">&quot;B&quot;</span>,<span style="color: #009900;">&quot;C&quot;</span>,<span style="color: #009900;">&quot;D&quot;</span>,<span style="color: #009900;">&quot;E&quot;</span>,<span style="color: #009900;">&quot;F&quot;</span>,<span style="color: #009900;">&quot;G&quot;</span>,<span style="color: #009900;">&quot;H&quot;</span>,<span style="color: #009900;">&quot;I&quot;</span>,<span style="color: #009900;">&quot;J&quot;</span>,<span style="color: #009900;">&quot;K&quot;</span>,<span style="color: #009900;">&quot;L&quot;</span>,<span style="color: #009900;">&quot;M&quot;</span>,<span style="color: #009900;">&quot;N&quot;</span>,<span style="color: #009900;">&quot;O&quot;</span>,<span style="color: #009900;">&quot;P&quot;</span>,<span style="color: #009900;">&quot;Q&quot;</span>,<br />
&nbsp; &nbsp;<span style="color: #009900;">&quot;R&quot;</span>,<span style="color: #009900;">&quot;S&quot;</span>,<span style="color: #009900;">&quot;T&quot;</span>,<span style="color: #009900;">&quot;U&quot;</span>,<span style="color: #009900;">&quot;V&quot;</span>,<span style="color: #009900;">&quot;W&quot;</span>,<span style="color: #009900;">&quot;X&quot;</span>,<span style="color: #009900;">&quot;Y&quot;</span>,<span style="color: #009900;">&quot;Z&quot;</span>,<span style="color: #009900;">&quot;a&quot;</span>,<span style="color: #009900;">&quot;b&quot;</span>,<span style="color: #009900;">&quot;c&quot;</span>,<span style="color: #009900;">&quot;d&quot;</span>,<span style="color: #009900;">&quot;e&quot;</span>,<span style="color: #009900;">&quot;f&quot;</span>,<span style="color: #009900;">&quot;g&quot;</span>,<span style="color: #009900;">&quot;h&quot;</span>,<span style="color: #009900;">&quot;i&quot;</span>,<span style="color: #009900;">&quot;j&quot;</span>,<br />
&nbsp; &nbsp;<span style="color: #009900;">&quot;k&quot;</span>,<span style="color: #009900;">&quot;l&quot;</span>,<span style="color: #009900;">&quot;m&quot;</span>,<span style="color: #009900;">&quot;n&quot;</span>,<span style="color: #009900;">&quot;o&quot;</span>,<span style="color: #009900;">&quot;p&quot;</span>,<span style="color: #009900;">&quot;q&quot;</span>,<span style="color: #009900;">&quot;r&quot;</span>,<span style="color: #009900;">&quot;s&quot;</span>,<span style="color: #009900;">&quot;t&quot;</span>,<span style="color: #009900;">&quot;u&quot;</span>,<span style="color: #009900;">&quot;v&quot;</span>,<span style="color: #009900;">&quot;w&quot;</span>,<span style="color: #009900;">&quot;x&quot;</span>,<span style="color: #009900;">&quot;y&quot;</span>,<span style="color: #009900;">&quot;z&quot;</span>,<span style="color: #009900;">&quot;0&quot;</span>,<span style="color: #009900;">&quot;1&quot;</span>,<span style="color: #009900;">&quot;2&quot;</span>,<br />
&nbsp; &nbsp;<span style="color: #009900;">&quot;3&quot;</span>,<span style="color: #009900;">&quot;4&quot;</span>,<span style="color: #009900;">&quot;5&quot;</span>,<span style="color: #009900;">&quot;6&quot;</span>,<span style="color: #009900;">&quot;7&quot;</span>,<span style="color: #009900;">&quot;8&quot;</span>,<span style="color: #009900;">&quot;9&quot;</span>,<span style="color: #009900;">&quot;-&quot;</span>,<span style="color: #009900;">&quot;.&quot;</span><br />
<br />
&nbsp; &nbsp;<span style="color: #666666; font-style: italic;">## The actual filter function</span><br />
&nbsp; &nbsp;<span style="color: #666699; font-weight: bold;">filter</span> encode <span style="color: #333;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;"># we have a hard-coded &quot;overflow&quot; value </span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #666699; font-weight: bold;">if</span><span style="color: #333;">&#40;</span><span style="color: #660033; font-weight: bold;">$_</span> <span style="color: #000066;">-ge</span> <span style="color: #333;">&#40;</span><span style="color: #660033; font-weight: bold;">$ody</span>.<span style="color: #003366;">Count</span> <span style="color: #66cc66;">*</span> <span style="color: #660033; font-weight: bold;">$ody</span>.<span style="color: #003366;">Count</span><span style="color: #333;">&#41;</span> <span style="color: #333;">&#41;</span> <span style="color: #333;">&#123;</span> <span style="color: #666699; font-weight: bold;">return</span> <span style="color: #009900;">&quot;__&quot;</span> <span style="color: #333;">&#125;</span> <br />
&nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; <span style="color: #660033; font-weight: bold;">$y</span> <span style="color: #66cc66;">=</span> <span style="color: #66cc66;">-</span><span style="color: #cc66cc;">1</span> &nbsp;<span style="color: #666666; font-style: italic;"># $y is a ref variable, so it has to be defined</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #660033; font-weight: bold;">$x</span> <span style="color: #66cc66;">=</span> <span style="color: #003366; font-weight: bold;"><span style="color: #333;">&#91;</span>Math<span style="color: #333;">&#93;</span></span>::<span style="color: #003366;">DivRem</span><span style="color: #333;">&#40;</span> <span style="color: #660033; font-weight: bold;">$_</span>, <span style="color: #660033; font-weight: bold;">$ody</span>.<span style="color: #003366;">Count</span>, <span style="color: #003366; font-weight: bold;"><span style="color: #333;">&#91;</span><span style="color: #003366; font-weight: bold;">ref</span><span style="color: #333;">&#93;</span></span><span style="color: #660033; font-weight: bold;">$y</span> <span style="color: #333;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #666699; font-weight: bold;">return</span> <span style="color: #009900;">&quot;$($ody[$x])$($ody[$y])&quot;</span><br />
&nbsp; &nbsp;<span style="color: #333;">&#125;</span><br />
&nbsp; &nbsp;<br />
&nbsp; &nbsp;<span style="color: #666666; font-style: italic;">## Handle numbers as parameters</span><br />
&nbsp; &nbsp;<span style="color: #666699; font-weight: bold;">foreach</span><span style="color: #333;">&#40;</span><span style="color: #660033; font-weight: bold;">$i</span> <span style="color: #666699; font-weight: bold;">in</span> <span style="color: #660033; font-weight: bold;">$args</span><span style="color: #333;">&#41;</span> <span style="color: #333;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #660033; font-weight: bold;">$i</span> <span style="color: #66cc66;">|</span> encode<br />
&nbsp; &nbsp;<span style="color: #333;">&#125;</span><br />
<span style="color: #333;">&#125;</span><br />
<span style="color: #666666; font-style: italic;">## Or handle numbers from the pipeline. We don't care :-)</span><br />
<span style="color: #666699; font-weight: bold;">PROCESS</span> <span style="color: #333;">&#123;</span><br />
&nbsp; &nbsp;<span style="color: #666699; font-weight: bold;">if</span><span style="color: #333;">&#40;</span><span style="color: #660033; font-weight: bold;">$_</span> <span style="color: #000066;">-ne</span> <span style="color: #660033; font-weight: bold;">$null</span><span style="color: #333;">&#41;</span> <span style="color: #333;">&#123;</span> <span style="color: #660033; font-weight: bold;">$_</span> <span style="color: #66cc66;">|</span> encode <span style="color: #333;">&#125;</span><br />
<span style="color: #333;">&#125;</span><br />
<span style="color: #333;">&#125;</span></div>

	<p>That&#8217;s the whole thing &#8230; it&#8217;s really only about three lines of code (including the definition of <code>$ody</code>), but the rest is necessary to make it handle parameters or pipeline values.  <img src='http://huddledmasses.org/wordpress/wp-includes/' alt=':D' class='wp-smiley' /> </p>]]></content:encoded>
			<wfw:commentRss>http://huddledmasses.org/google-charts-from-powershell-1/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

