<?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; REST</title>
	<atom:link href="http://huddledmasses.org/tag/rest/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>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>Get-Web (Another round of wget for PowerShell)</title>
		<link>http://huddledmasses.org/get-web-another-round-of-wget-for-powershell/</link>
		<comments>http://huddledmasses.org/get-web-another-round-of-wget-for-powershell/#comments</comments>
		<pubDate>Fri, 02 May 2008 02:08:08 +0000</pubDate>
		<dc:creator>Joel 'Jaykul' Bennett</dc:creator>
				<category><![CDATA[Huddled]]></category>
		<category><![CDATA[Get-Web]]></category>
		<category><![CDATA[Http]]></category>
		<category><![CDATA[HttpWebRequest]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[REST]]></category>
		<category><![CDATA[Scripting]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[wGet]]></category>
		<category><![CDATA[Xml]]></category>

		<guid isPermaLink="false">http://HuddledMasses.org/?p=520</guid>
		<description><![CDATA[Well, after multiple attempts at a wget PowerShell script (the last one works very well for downloading web pages, files, as long as you don&#8217;t need to send post parameters or anything like that) ... I found myself writing a script last week that included a custom HTTP POST function as well as using some [...]]]></description>
			<content:encoded><![CDATA[	<p>Well, after multiple attempts at a <a href="http://huddledmasses.org/wget-2-for-powershell/">wget PowerShell script</a> (the last one works very well for downloading web pages, files, as long as you don&#8217;t need to send post parameters or anything like that) ... I found myself writing a script last week that included a custom <span class="caps">HTTP</span> <span class="caps">POST</span> function as well as using some prior functionality I wrote (<code>ConvertFrom-Html</code>) to convert <span class="caps">HTML</span> files to <span class="caps">XML</span> documents &#8212; which PowerShell can deal with nicely.</p>

	<p>So I&#8217;ve taken my <a href="http://huddledmasses.org/converting-html-to-xml-in-powershell/">Huddled.Html</a> code and worked it in together with a few extra bits &#8230; and I&#8217;m releasing it under the new name &#8220;PoshHttp&#8221; (which has the sole benefit of being short, in the case when you need to type the full command names, like: <code>PoshHttp\Get-Web</code>.</p>

	<p>In lieu of providing proper documentation for this, there&#8217;s a script below which shows off some of the features of the <code>Get-Web</code> cmdlet &#8230; but first, you&#8217;re going to want to <a href="/downloads/PoshHttp.7z">download PoshHttp</a> and I can give you a basic overview.</p>

	<h4>Get-Web </h4>

	<p>Downloads a file from the web <span class="caps">URI</span>, optionally passing <span class="caps">POST</span> or <span class="caps">GET</span> parameters which it accepts as a Hashtable. If the resulting file is an xml or html file, it converts it to <span class="caps">XML</span> and outputs it as an <code>XmlDocument</code> object. If they are not, it saves them to file, and outputs the <code>FileInfo</code> object. </p>

	<ul>
		<li><strong>Plain</strong> will prevent the conversion to xml</li>
		<li><strong>Save</strong> will force saving to file (either xml or binaries)</li>
		<li><strong>Path</strong> lets you specify the file name/path (normally, it selects a path based on what you&#8217;re downloading).</li>
	</ul>
	<ul>
		<li><strong>Force</strong> will prevent it from asking if you want to overwrite files</li>
	</ul>

	<h4>ConvertFrom-Html</h4>

	<p>Converts <span class="caps">HTML</span> to <span class="caps">XML</span>. I&#8217;ll eventually tweak this so it supports passing it a file path and even saving the xml in-place on the original file &#8230; but for now you can use it on a stream of text, like this: <code>(Get-Content file.html | ConvertFrom-Html).save( &#34;file.xml&#34; )</code>.  Note that it outputs an xmldocument object &#8230; you can get the xml as text to the console using <code>Get_OuterXml()</code>.</p>

	<h4> ConvertTo-Hashtable</h4>

	<p>Converts a url-style query string or NameValueCollection into a Hashtable. It&#8217;s mainly to make it easier to use the Get-Web in cases where you&#8217;re getting the <span class="caps">URL</span> or <span class="caps">POST</span> data from elsewhere.</p>

	<p>Here&#8217;s a script with a few example uses of Get-Web: <span id="more-520"></span></p>

	<div class="posh code posh" style="font-family:monospace;"><br />
<span style="color: #666666; font-style: italic;">## Find the url of the image (download an html file as an xmldocument)</span><br />
<span style="color: #660033; font-weight: bold;">$ImgURL</span> <span style="color: #66cc66;">=</span> <span style="color: #333;">&#40;</span><span style="color: #0066cc; font-style: italic;">Get-<span style="font-style: normal;">Web</span></span> http:<span style="color: #66cc66;">//</span>dilbert.<span style="color: #003366;">com</span><span style="color: #66cc66;">/</span>fast<span style="color: #66cc66;">/</span><span style="color: #333;">&#41;</span>.<span style="color: #003366;">html</span>.<span style="color: #003366;">body</span>.<span style="color: #003366;">div</span>.<span style="color: #003366;">img</span>.<span style="color: #003366;">src</span><br />
<br />
<span style="color: #666699; font-weight: bold;">if</span><span style="color: #333;">&#40;</span><span style="color: #660033; font-weight: bold;">$Host</span>.<span style="color: #003366;">Name</span> <span style="color: #000066;">-eq</span> <span style="color: #009900;">&quot;PoshConsole&quot;</span><span style="color: #333;">&#41;</span> <span style="color: #333;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">#In PoshConsole, show it inline</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #660033; font-weight: bold;">$ImgUrl</span> <span style="color: #66cc66;">|</span> <span style="color: #0066cc; font-style: italic;">Out-<span style="font-style: normal;">WPF</span></span> <span style="color: #000066;">-source</span> <span style="color: #009900;">&quot;&lt;Image Height='174' Source='{Binding Path=AbsoluteUri}' xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation' /&gt;&quot;</span><br />
<span style="color: #333;">&#125;</span> <span style="color: #666699; font-weight: bold;">else</span> <span style="color: #333;">&#123;</span><br />
&nbsp; &nbsp;<span style="color: #666666; font-style: italic;">## Use Get-Web to download an image (it's saved to file by default), and open it in my default viewer</span><br />
&nbsp; &nbsp;<span style="color: #666666; font-style: italic;">## When Get-Web saves a file, it outputs the [FileInfo] which can be invoked with &amp;</span><br />
&nbsp; &nbsp;<span style="color: #66cc66;">&amp;</span><span style="color: #333;">&#40;</span><span style="color: #0066cc; font-style: italic;">Get-<span style="font-style: normal;">Web</span></span> <span style="color: #009900;">&quot;http://dilbert.com$ImgURL&quot;</span> <span style="color: #000066;">-force</span><span style="color: #333;">&#41;</span><br />
<span style="color: #333;">&#125;</span><br />
<br />
<span style="color: #666666; font-style: italic;">###################################################################################################</span><br />
<span style="color: #666666; font-style: italic;">## Determine the language of a snippet of text (5 words minimum for best results)</span><br />
<span style="color: #666699; font-weight: bold;">function</span> <span style="color: #0066cc; font-style: italic;">Resolve-<span style="font-style: normal;">Language</span></span><span style="color: #333;">&#40;</span><span style="color: #003366; font-weight: bold;"><span style="color: #333;">&#91;</span><span style="color: #003366; font-weight: bold;">string</span><span style="color: #333;">&#93;</span></span><span style="color: #660033; font-weight: bold;">$text</span><span style="color: #333;">&#41;</span> <span style="color: #333;">&#123;</span><br />
&nbsp; &nbsp;<span style="color: #666666; font-style: italic;">## This time, we're using Get-Web with POST parameters ...</span><br />
&nbsp; &nbsp;<span style="color: #666699; font-weight: bold;">return</span> <span style="color: #333;">&#40;</span><span style="color: #0066cc; font-style: italic;">Get-<span style="font-style: normal;">Web</span></span> <span style="color: #009900;">&quot;http://www.xrce.xerox.com/cgi-bin/mltt/LanguageGuesser&quot;</span> <span style="color: #000066;">-Post</span> <span style="color: #333;">&#40;</span>@<span style="color: #333;">&#123;</span>Text<span style="color: #66cc66;">=</span><span style="color: #660033; font-weight: bold;">$text</span><span style="color: #333;">&#125;</span><span style="color: #333;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #333;">&#41;</span>.<span style="color: #003366;">SelectSingleNode</span><span style="color: #333;">&#40;</span><span style="color: #009900;">&quot;//font&quot;</span><span style="color: #333;">&#41;</span>.<span style="color: #009900;">&quot;#text&quot;</span>.<span style="color: #003366;">Trim</span><span style="color: #333;">&#40;</span><span style="color: #333;">&#41;</span><br />
<span style="color: #333;">&#125;</span><br />
<br />
<span style="color: #666666; font-style: italic;">###################################################################################################</span><br />
<span style="color: #666666; font-style: italic;">## Translate text to English ... This is obviously reworkable as a general translation tool</span><br />
<span style="color: #666666; font-style: italic;">## But I don't have much use for that, since I only speak Spanish, English, and code ...</span><br />
<span style="color: #666699; font-weight: bold;">function</span> <span style="color: #0066cc; font-style: italic;">Get-<span style="font-style: normal;">English</span></span><span style="color: #333;">&#40;</span><span style="color: #003366; font-weight: bold;"><span style="color: #333;">&#91;</span><span style="color: #003366; font-weight: bold;">string</span><span style="color: #333;">&#93;</span></span><span style="color: #660033; font-weight: bold;">$text</span>,<span style="color: #003366; font-weight: bold;"><span style="color: #333;">&#91;</span><span style="color: #003366; font-weight: bold;">string</span><span style="color: #333;">&#93;</span></span><span style="color: #660033; font-weight: bold;">$FromLanguage</span><span style="color: #333;">&#41;</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: #66cc66;">!</span><span style="color: #660033; font-weight: bold;">$FromLanguage</span><span style="color: #333;">&#41;</span> <span style="color: #333;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #660033; font-weight: bold;">$FromLanguage</span> <span style="color: #66cc66;">=</span> <span style="color: #0066cc; font-style: italic;">Resolve-<span style="font-style: normal;">Language</span></span> <span style="color: #660033; font-weight: bold;">$text</span><br />
&nbsp; &nbsp;<span style="color: #333;">&#125;</span><br />
&nbsp; &nbsp;<span style="color: #660033; font-weight: bold;">$post</span> <span style="color: #66cc66;">=</span> @<span style="color: #333;">&#123;</span>text<span style="color: #66cc66;">=</span><span style="color: #660033; font-weight: bold;">$text</span><span style="color: #333;">&#125;</span><br />
&nbsp; &nbsp;<span style="color: #666699; font-weight: bold;">switch</span><span style="color: #333;">&#40;</span><span style="color: #660033; font-weight: bold;">$FromLanguage</span><span style="color: #333;">&#41;</span> <span style="color: #333;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #009900;">&quot;Arabic&quot;</span> &nbsp; &nbsp; &nbsp; <span style="color: #333;">&#123;</span> <span style="color: #660033; font-weight: bold;">$post</span><span style="color: #333;">&#91;</span><span style="color: #009900;">&quot;langpair&quot;</span><span style="color: #333;">&#93;</span> <span style="color: #66cc66;">=</span> <span style="color: #009900;">&quot;ar|en&quot;</span> <span style="color: #333;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #009900;">&quot;Chinese&quot;</span> &nbsp; &nbsp; &nbsp;<span style="color: #333;">&#123;</span> <span style="color: #660033; font-weight: bold;">$post</span><span style="color: #333;">&#91;</span><span style="color: #009900;">&quot;langpair&quot;</span><span style="color: #333;">&#93;</span> <span style="color: #66cc66;">=</span> <span style="color: #009900;">&quot;zh|en&quot;</span> <span style="color: #333;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #009900;">&quot;Dutch&quot;</span> &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #333;">&#123;</span> <span style="color: #660033; font-weight: bold;">$post</span><span style="color: #333;">&#91;</span><span style="color: #009900;">&quot;langpair&quot;</span><span style="color: #333;">&#93;</span> <span style="color: #66cc66;">=</span> <span style="color: #009900;">&quot;nl|en&quot;</span> <span style="color: #333;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #009900;">&quot;French&quot;</span> &nbsp; &nbsp; &nbsp; <span style="color: #333;">&#123;</span> <span style="color: #660033; font-weight: bold;">$post</span><span style="color: #333;">&#91;</span><span style="color: #009900;">&quot;langpair&quot;</span><span style="color: #333;">&#93;</span> <span style="color: #66cc66;">=</span> <span style="color: #009900;">&quot;fr|en&quot;</span> <span style="color: #333;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #009900;">&quot;German&quot;</span> &nbsp; &nbsp; &nbsp; <span style="color: #333;">&#123;</span> <span style="color: #660033; font-weight: bold;">$post</span><span style="color: #333;">&#91;</span><span style="color: #009900;">&quot;langpair&quot;</span><span style="color: #333;">&#93;</span> <span style="color: #66cc66;">=</span> <span style="color: #009900;">&quot;de|en&quot;</span> <span style="color: #333;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #009900;">&quot;Greek&quot;</span> &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #333;">&#123;</span> <span style="color: #660033; font-weight: bold;">$post</span><span style="color: #333;">&#91;</span><span style="color: #009900;">&quot;langpair&quot;</span><span style="color: #333;">&#93;</span> <span style="color: #66cc66;">=</span> <span style="color: #009900;">&quot;el|en&quot;</span> <span style="color: #333;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #009900;">&quot;Italian&quot;</span> &nbsp; &nbsp; &nbsp;<span style="color: #333;">&#123;</span> <span style="color: #660033; font-weight: bold;">$post</span><span style="color: #333;">&#91;</span><span style="color: #009900;">&quot;langpair&quot;</span><span style="color: #333;">&#93;</span> <span style="color: #66cc66;">=</span> <span style="color: #009900;">&quot;it|en&quot;</span> <span style="color: #333;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #009900;">&quot;Japanese&quot;</span> &nbsp; &nbsp; <span style="color: #333;">&#123;</span> <span style="color: #660033; font-weight: bold;">$post</span><span style="color: #333;">&#91;</span><span style="color: #009900;">&quot;langpair&quot;</span><span style="color: #333;">&#93;</span> <span style="color: #66cc66;">=</span> <span style="color: #009900;">&quot;ja|en&quot;</span> <span style="color: #333;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #009900;">&quot;Korean&quot;</span> &nbsp; &nbsp; &nbsp; <span style="color: #333;">&#123;</span> <span style="color: #660033; font-weight: bold;">$post</span><span style="color: #333;">&#91;</span><span style="color: #009900;">&quot;langpair&quot;</span><span style="color: #333;">&#93;</span> <span style="color: #66cc66;">=</span> <span style="color: #009900;">&quot;ko|en&quot;</span> <span style="color: #333;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #009900;">&quot;Portuguese&quot;</span> &nbsp; <span style="color: #333;">&#123;</span> <span style="color: #660033; font-weight: bold;">$post</span><span style="color: #333;">&#91;</span><span style="color: #009900;">&quot;langpair&quot;</span><span style="color: #333;">&#93;</span> <span style="color: #66cc66;">=</span> <span style="color: #009900;">&quot;pt|en&quot;</span> <span style="color: #333;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #009900;">&quot;Russian&quot;</span> &nbsp; &nbsp; &nbsp;<span style="color: #333;">&#123;</span> <span style="color: #660033; font-weight: bold;">$post</span><span style="color: #333;">&#91;</span><span style="color: #009900;">&quot;langpair&quot;</span><span style="color: #333;">&#93;</span> <span style="color: #66cc66;">=</span> <span style="color: #009900;">&quot;ru|en&quot;</span> <span style="color: #333;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #009900;">&quot;Spanish&quot;</span> &nbsp; &nbsp; &nbsp;<span style="color: #333;">&#123;</span> <span style="color: #660033; font-weight: bold;">$post</span><span style="color: #333;">&#91;</span><span style="color: #009900;">&quot;langpair&quot;</span><span style="color: #333;">&#93;</span> <span style="color: #66cc66;">=</span> <span style="color: #009900;">&quot;es|en&quot;</span> <span style="color: #333;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; default <span style="color: #333;">&#123;</span> <span style="color: #666699; font-weight: bold;">return</span> <span style="color: #009900;">&quot;Sorry, but I can't translate $FromLanguage&quot;</span> <span style="color: #333;">&#125;</span><br />
&nbsp; &nbsp;<span style="color: #333;">&#125;</span><br />
&nbsp; &nbsp;<br />
&nbsp; &nbsp;<span style="color: #666666; font-style: italic;">## Using Get-Web with POST parameters ... nothing remarkable, but it's just nice with the previous function ...</span><br />
&nbsp; &nbsp;<span style="color: #666699; font-weight: bold;">return</span> <span style="color: #333;">&#40;</span><span style="color: #0066cc; font-style: italic;">Get-<span style="font-style: normal;">Web</span></span> <span style="color: #009900;">&quot;http://www.google.com/translate_t&quot;</span> <span style="color: #000066;">-Post</span> <span style="color: #660033; font-weight: bold;">$post</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #333;">&#41;</span>.<span style="color: #003366;">SelectSingleNode</span><span style="color: #333;">&#40;</span><span style="color: #009900;">&quot;//div[@id='result_box']&quot;</span><span style="color: #333;">&#41;</span>.<span style="color: #009900;">&quot;#text&quot;</span>.<span style="color: #003366;">Trim</span><span style="color: #333;">&#40;</span><span style="color: #333;">&#41;</span><br />
<span style="color: #333;">&#125;</span><br />
<br />
<br />
<span style="color: #666666; font-style: italic;">####################################</span><br />
<span style="color: #666666; font-style: italic;">## Figure out the real url behind those shortened forms</span><br />
<span style="color: #666699; font-weight: bold;">function</span> <span style="color: #0066cc; font-style: italic;">Resolve-<span style="font-style: normal;">URL</span></span><span style="color: #333;">&#40;</span><span style="color: #003366; font-weight: bold;"><span style="color: #333;">&#91;</span><span style="color: #003366; font-weight: bold;">string</span><span style="color: #333;">&#91;</span><span style="color: #333;">&#93;</span><span style="color: #333;">&#93;</span></span><span style="color: #660033; font-weight: bold;">$urls</span><span style="color: #333;">&#41;</span> <span style="color: #333;">&#123;</span> <br />
&nbsp; &nbsp;<span style="color: #003366; font-weight: bold;"><span style="color: #333;">&#91;</span><span style="color: #003366; font-weight: bold;">regex</span><span style="color: #333;">&#93;</span></span><span style="color: #660033; font-weight: bold;">$snip</span> &nbsp;<span style="color: #66cc66;">=</span> <span style="color: #009900;">&quot;(?:https?://)?(?:snurl|snipr|snipurl)\.com/([^?/ ]*)\b&quot;</span><br />
&nbsp; &nbsp;<span style="color: #003366; font-weight: bold;"><span style="color: #333;">&#91;</span><span style="color: #003366; font-weight: bold;">regex</span><span style="color: #333;">&#93;</span></span><span style="color: #660033; font-weight: bold;">$tiny</span> &nbsp;<span style="color: #66cc66;">=</span> <span style="color: #009900;">&quot;(?:https?://)?TinyURL.com/([^?/ ]*)\b&quot;</span><br />
&nbsp; &nbsp;<span style="color: #003366; font-weight: bold;"><span style="color: #333;">&#91;</span><span style="color: #003366; font-weight: bold;">regex</span><span style="color: #333;">&#93;</span></span><span style="color: #660033; font-weight: bold;">$isgd</span> &nbsp;<span style="color: #66cc66;">=</span> <span style="color: #009900;">&quot;(?:https?://)?is.gd/([^?/ ]*)\b&quot;</span><br />
&nbsp; &nbsp;<span style="color: #003366; font-weight: bold;"><span style="color: #333;">&#91;</span><span style="color: #003366; font-weight: bold;">regex</span><span style="color: #333;">&#93;</span></span><span style="color: #660033; font-weight: bold;">$twurl</span> <span style="color: #66cc66;">=</span> <span style="color: #009900;">&quot;(?:https?://)?twurl.nl/([^?/ ]*)\b&quot;</span><br />
<br />
&nbsp; &nbsp;<span style="color: #666699; font-weight: bold;">switch</span> <span style="color: #000066;">-regex</span> <span style="color: #333;">&#40;</span><span style="color: #660033; font-weight: bold;">$urls</span><span style="color: #333;">&#41;</span> <span style="color: #333;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #660033; font-weight: bold;">$snip</span> <span style="color: #333;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #666666; font-style: italic;">## Notice that {{ Get-Web ... -plain }} returns plain text, not an xml doc</span><br />
&nbsp; &nbsp; &nbsp; &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;">$snip</span>.<span style="color: #333399; font-weight: bold; font-style: italic;">Replace</span><span style="color: #333;">&#40;</span> <span style="color: #660033; font-weight: bold;">$_</span>, <span style="color: #333;">&#40;</span><span style="color: #0066cc; font-style: italic;">Get-<span style="font-style: normal;">Web</span></span> <span style="color: #009900;">&quot;http://snipurl.com/resolveurl?id=$($snip.match( $_ ).groups[1].value)&quot;</span> <span style="color: #000066;">-plain</span><span style="color: #333;">&#41;</span><span style="color: #333;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #333;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #660033; font-weight: bold;">$tiny</span> <span style="color: #333;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #666666; font-style: italic;">## GET parameters this time ...</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #660033; font-weight: bold;">$doc</span> <span style="color: #66cc66;">=</span> <span style="color: #0066cc; font-style: italic;">Get-<span style="font-style: normal;">Web</span></span> <span style="color: #009900;">&quot;http://tinyurl.com/preview.php&quot;</span> <span style="color: #000066;">-Get</span> @<span style="color: #333;">&#123;</span>num<span style="color: #66cc66;">=</span><span style="color: #660033; font-weight: bold;">$tiny</span>.<span style="color: #333399; font-weight: bold; font-style: italic;">match</span><span style="color: #333;">&#40;</span> <span style="color: #660033; font-weight: bold;">$_</span> <span style="color: #333;">&#41;</span>.<span style="color: #003366;">groups</span><span style="color: #333;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #333;">&#93;</span>.<span style="color: #003366;">value</span><span style="color: #333;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &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;">$tiny</span>.<span style="color: #333399; font-weight: bold; font-style: italic;">Replace</span><span style="color: #333;">&#40;</span> <span style="color: #660033; font-weight: bold;">$_</span>, <span style="color: #009900;">&quot;$($doc.SelectSingleNode(&quot;</span><span style="color: #009900;">&quot;//a[@id='redirecturl']&quot;</span><span style="color: #009900;">&quot;).href)&quot;</span> <span style="color: #333;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #333;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #660033; font-weight: bold;">$isgd</span> <span style="color: #333;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #660033; font-weight: bold;">$doc</span> <span style="color: #66cc66;">=</span> <span style="color: #0066cc; font-style: italic;">Get-<span style="font-style: normal;">Web</span></span> <span style="color: #009900;">&quot;http://is.gd/$($isgd.match( $_ ).groups[1].value)-&quot;</span><br />
&nbsp; &nbsp; &nbsp; &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;">$isgd</span>.<span style="color: #333399; font-weight: bold; font-style: italic;">Replace</span><span style="color: #333;">&#40;</span> <span style="color: #660033; font-weight: bold;">$_</span>, <span style="color: #009900;">&quot;$($doc.SelectSingleNode(&quot;</span><span style="color: #009900;">&quot;//div[@id='main']/p/a&quot;</span><span style="color: #009900;">&quot;).href)&quot;</span><span style="color: #333;">&#41;</span> <br />
&nbsp; &nbsp; &nbsp; <span style="color: #333;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #660033; font-weight: bold;">$twurl</span> <span style="color: #333;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #660033; font-weight: bold;">$doc</span> <span style="color: #66cc66;">=</span> <span style="color: #0066cc; font-style: italic;">Get-<span style="font-style: normal;">Web</span></span> <span style="color: #009900;">&quot;http://tweetburner.com/links/$($twurl.match( $_ ).groups[1].value)&quot;</span><br />
&nbsp; &nbsp; &nbsp; &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;">$twurl</span>.<span style="color: #333399; font-weight: bold; font-style: italic;">Replace</span><span style="color: #333;">&#40;</span><span style="color: #660033; font-weight: bold;">$_</span>, <span style="color: #009900;">&quot;$($doc.selectsingleNode(&quot;</span><span style="color: #009900;">&quot;//div[@id='main-content']/p/a&quot;</span><span style="color: #009900;">&quot;).href)&quot;</span> <span style="color: #333;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #333;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; default <span style="color: #333;">&#123;</span> <span style="color: #0066cc; font-style: italic;">write-<span style="font-style: normal;">output</span></span> <span style="color: #660033; font-weight: bold;">$_</span> <span style="color: #333;">&#125;</span><br />
&nbsp; &nbsp;<span style="color: #333;">&#125;</span><br />
<span style="color: #333;">&#125;</span></div>]]></content:encoded>
			<wfw:commentRss>http://huddledmasses.org/get-web-another-round-of-wget-for-powershell/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

