<?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>Development in a Blink</title>
	<atom:link href="http://www.dougfinke.com/blog/index.php/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.dougfinke.com/blog</link>
	<description>Researching the optimal; implementing the practical</description>
	<lastBuildDate>Fri, 03 May 2013 19:47:05 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5.1</generator>
		<item>
		<title>50% off My book PowerShell for Developers</title>
		<link>http://www.dougfinke.com/blog/index.php/2013/05/03/my-book-powershell-for-developers-12-off/</link>
		<comments>http://www.dougfinke.com/blog/index.php/2013/05/03/my-book-powershell-for-developers-12-off/#comments</comments>
		<pubDate>Fri, 03 May 2013 19:46:25 +0000</pubDate>
		<dc:creator>Doug Finke</dc:creator>
				<category><![CDATA[O'Reilly]]></category>
		<category><![CDATA[PowerShell]]></category>

		<guid isPermaLink="false">http://www.dougfinke.com/blog/?p=1534</guid>
		<description><![CDATA[OReilly Media celebrates Day Against DRM, 1/2 off Ebooks+Videos Use code: DRM2013 Today only! Includes my book too PowerShell for Developers http://oreil.ly/DRM-FREE-2013]]></description>
				<content:encoded><![CDATA[<p>OReilly Media celebrates Day Against DRM, 1/2 off Ebooks+Videos</p>
<p>Use code: DRM2013</p>
<p>Today only!</p>
<p>Includes my book too <a href="http://shop.oreilly.com/product/0636920024491.do">PowerShell for Developers</a>    <br /><a href="http://oreil.ly/DRM-FREE-2013">http://oreil.ly/DRM-FREE-2013</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.dougfinke.com/blog/index.php/2013/05/03/my-book-powershell-for-developers-12-off/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PowerShell Automation</title>
		<link>http://www.dougfinke.com/blog/index.php/2013/04/18/powershell-automation/</link>
		<comments>http://www.dougfinke.com/blog/index.php/2013/04/18/powershell-automation/#comments</comments>
		<pubDate>Fri, 19 Apr 2013 01:04:20 +0000</pubDate>
		<dc:creator>Doug Finke</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.dougfinke.com/blog/?p=1532</guid>
		<description><![CDATA[]]></description>
				<content:encoded><![CDATA[<p><a href="http://www.dougfinke.com/blog/wp-content/uploads/2013/04/UseAutomation.png"><img title="UseAutomation" style="border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; float: none; padding-top: 0px; padding-left: 0px; margin-left: auto; border-left: 0px; display: block; padding-right: 0px; margin-right: auto" border="0" alt="UseAutomation" src="http://www.dougfinke.com/blog/wp-content/uploads/2013/04/UseAutomation_thumb.png" width="355" height="445" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.dougfinke.com/blog/index.php/2013/04/18/powershell-automation/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Creating a PowerShell Translate Function</title>
		<link>http://www.dougfinke.com/blog/index.php/2013/03/31/creating-a-powershell-translate-function/</link>
		<comments>http://www.dougfinke.com/blog/index.php/2013/03/31/creating-a-powershell-translate-function/#comments</comments>
		<pubDate>Sun, 31 Mar 2013 17:40:14 +0000</pubDate>
		<dc:creator>Doug Finke</dc:creator>
				<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://www.dougfinke.com/blog/?p=1528</guid>
		<description><![CDATA[The Python language has a translate and maketrans function that are typically used in substitution ciphers. translate The method translate() returns a copy of the string in which all characters have been translated using table (constructed with the maketrans() function in the string module), optionally deleting all characters found in the string deletechars. maketrans The [...]]]></description>
				<content:encoded><![CDATA[<p>The Python language has a <strong><em><a href="http://www.tutorialspoint.com/python/string_translate.htm">translate</a></em></strong> and <strong><em><a href="http://www.tutorialspoint.com/python/string_maketrans.htm">maketrans</a></em></strong> function that are typically used in <a href="http://en.wikipedia.org/wiki/Substitution_cipher">substitution ciphers</a><em><strong></strong></em>.</p>
<table cellspacing="0" cellpadding="2" width="551" border="0">
<tbody>
<tr>
<td valign="top" width="200"><a href="http://www.tutorialspoint.com/python/string_translate.htm">translate</a></td>
<td valign="top" width="349">The method <b><a href="http://www.tutorialspoint.com/python/string_translate.htm">translate</a>()</b> returns a copy of the string in which all characters have been translated using <i>table</i> (constructed with the <a href="http://www.tutorialspoint.com/python/string_maketrans.htm">maketrans</a>() function in the string module), optionally deleting all characters found in the string <i>deletechars</i>.           </td>
</tr>
<tr>
<td valign="top" width="200"><a href="http://www.tutorialspoint.com/python/string_maketrans.htm">maketrans</a></td>
<td valign="top" width="349">The method <b><a href="http://www.tutorialspoint.com/python/string_maketrans.htm">maketrans</a>()</b> returns a translation table that maps each character in the <i>intab</i> string into the character at the same position in the <i>outtab</i> string. Then this table is passed to the <a href="http://www.tutorialspoint.com/python/string_translate.htm">translate</a>() function.</td>
</tr>
</tbody>
</table>
<h3>Using it in PowerShell</h3>
<p>I created two PowerShell functions to mirror the Python ones <strong><em>Invoke-Translate</em></strong>&#160; and <em><strong>New-TranslationTable</strong></em>.</p>
<p>The following example shows the usage of&#160; <strong><em>Invoke-Translate</em></strong>. Here, every vowel in a string is replaced by its vowel position.</p>
<pre class="PowerShellColorizedScript" style="height: 178px; width: 542px"><span style="color: #ff4500">$InputTable</span> <span style="color: #a9a9a9">=</span> <span style="color: #8b0000">&quot;aeiou&quot;</span>            
<span style="color: #ff4500">$OutputTable</span> <span style="color: #a9a9a9">=</span> <span style="color: #8b0000">&quot;12345&quot;</span>            
<span style="color: #ff4500">$TranslationTable</span> <span style="color: #a9a9a9">=</span> <span style="color: #0000ff">New-TranslationTable</span> <span style="color: #ff4500">$InputTable</span> <span style="color: #ff4500">$OutputTable</span>            
            
<span style="color: #ff4500">$string</span> <span style="color: #a9a9a9">=</span> <span style="color: #8b0000">&quot;this is string example....wow!!!&quot;</span><span style="color: #000000">;</span>            
            
<span style="color: #0000ff">Invoke-Translate</span> <span style="color: #ff4500">$string</span> <span style="color: #ff4500">$TranslationTable</span>             
                      
<span style="color: #006400">th3s 3s str3ng 2x1mpl2....w4w!!!</span>            </pre>
<p>This example deletes all &#8216;x&#8217; and &#8216;m&#8217; characters from the string before doing the translate.</p>
<pre class="PowerShellColorizedScript" style="height: 167px; width: 551px"><span style="color: #ff4500">$InputTable</span> <span style="color: #a9a9a9">=</span> <span style="color: #8b0000">&quot;aeiou&quot;</span>            
<span style="color: #ff4500">$OutputTable</span> <span style="color: #a9a9a9">=</span> <span style="color: #8b0000">&quot;12345&quot;</span>            
<span style="color: #ff4500">$TranslationTable</span> <span style="color: #a9a9a9">=</span> <span style="color: #0000ff">New-TranslationTable</span> <span style="color: #ff4500">$InputTable</span> <span style="color: #ff4500">$OutputTable</span>            
            
<span style="color: #ff4500">$string</span> <span style="color: #a9a9a9">=</span> <span style="color: #8b0000">&quot;this is string example....wow!!!&quot;</span><span style="color: #000000">;</span>            
            
<span style="color: #0000ff">Invoke-Translate</span> <span style="color: #ff4500">$string</span> <span style="color: #ff4500">$TranslationTable</span> <span style="color: #8b0000">'xm'</span>             
            
<span style="color: #006400">th3s 3s str3ng 21pl2....w4w!!!</span></pre>
<h3>Grab the PowerShell Script</h3>
<p><a href="http://goo.gl/TX7vp"><img title="Octocat" style="border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; float: left; padding-top: 0px; padding-left: 0px; border-left: 0px; display: inline; padding-right: 0px" border="0" alt="Octocat" align="left" src="http://www.dougfinke.com/blog/wp-content/uploads/2013/03/Octocat.jpg" width="86" height="72" /></a></p>
<p>The PowerShell script is <a href="http://goo.gl/TX7vp">here on GitHub</a>.</p>
<p>Have fun!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dougfinke.com/blog/index.php/2013/03/31/creating-a-powershell-translate-function/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>How to run PowerShell from node.js</title>
		<link>http://www.dougfinke.com/blog/index.php/2013/02/26/how-to-run-powershell-from-node-js/</link>
		<comments>http://www.dougfinke.com/blog/index.php/2013/02/26/how-to-run-powershell-from-node-js/#comments</comments>
		<pubDate>Wed, 27 Feb 2013 00:59:15 +0000</pubDate>
		<dc:creator>Doug Finke</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[node.js]]></category>
		<category><![CDATA[PowerShell]]></category>

		<guid isPermaLink="false">http://www.dougfinke.com/blog/?p=1524</guid>
		<description><![CDATA[Tomasz Janczuk of Microsoft posted about owin, .NET and node.js. Here is the project on github. The owin project allows hosting .NET 4.5 code in node.js applications running on Windows. You need Windows x64 with node.js 0.8.x x64 installed (the module had been developed against node.js 0.8.19). You also need .NET Framework 4.5 on the [...]]]></description>
				<content:encoded><![CDATA[<p>Tomasz Janczuk of Microsoft <a href="http://tomasz.janczuk.org/2013/02/cpu-bound-workers-for-nodejs.html">posted</a> about <a href="https://github.com/tjanczuk/owin">owin</a>, .NET and node.js. Here is <a href="https://github.com/tjanczuk/owin">the project on github</a>.</p>
<blockquote><p>The <a href="https://github.com/tjanczuk/owin">owin</a> project allows hosting .NET 4.5 code in node.js applications running on Windows.</p>
</blockquote>
<p>You need Windows x64 with node.js 0.8.x x64 installed (the module had been developed against node.js <a href="http://nodejs.org/dist/v0.8.19/">0.8.19</a>). You also need <a href="http://www.microsoft.com/en-us/download/details.aspx?id=30653">.NET Framework 4.5</a> on the machine.</p>
<h3>PowerShell + node.js</h3>
<p>Below is the PowerShell script at work.</p>
<blockquote><p>The <a href="http://tomasz.janczuk.org/2013/02/hosting-net-code-in-nodejs-applications.html">owin</a> module allows running CPU-bound computations implemented in .NET in-process with the node.js application without blocking the node.js event loop.</p>
</blockquote>
<p><a href="http://www.dougfinke.com/blog/wp-content/uploads/2013/02/image.png"><img title="image" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="image" src="http://www.dougfinke.com/blog/wp-content/uploads/2013/02/image_thumb.png" width="570" height="245" /></a></p>
<h3>The PowerShell script and C# implementation</h3>
<p>The script has three steps:</p>
<ol>
<li>Compiles the C# which implements calling PowerShell as a Owinjs.Worker. This first step compiles to a DLL the C# implementing the PowerShell call simulating a CPU-bound computation. Simply, it calculates <em>income</em> by subtracting the <em>cost </em>from the <em>revenue</em> passed in from the JavaScript and does a <em>Start-Sleep 5</em> to become CPU-bound. </li>
<li>Next it takes the JavaScript, does a <em>Set-Content</em> to a file <em>test.js</em>. </li>
<li>Finally, we invoke <em>node </em>on the <em>test.js</em> file created in step 2 </li>
</ol>
<blockquote><h3>Note: You also need the <font style="font-weight: bold">Owinjs.dll </font>in the same directory as the script to make this happen. Download the zip file at the end of the post.</h3>
</blockquote>
<pre class="PowerShellColorizedScript"><span style="color: #ff4500">$ReferencedAssemblies</span> <span style="color: #a9a9a9">=</span> <span style="color: #8b0000">&quot;$pwd\Owinjs.dll&quot;</span>            
            
<span style="color: #ff4500">$powerShell</span> <span style="color: #a9a9a9">=</span> <span style="color: #8b0000">@&quot;

using System.Collections.Generic;
using System.Management.Automation;

namespace CalculateBudget
{
    public class Startup : Owinjs.Worker
    {
        protected override IDictionary<string string ,> Execute(IDictionary<string string ,> input)
        {
            var script = string.Format(@&quot;{0}-{1} ; Start-Sleep 5&quot;, 
                input[&quot;revenue&quot;], 
                input[&quot;cost&quot;]);

            var income = PowerShell
                .Create()
                .AddScript(script)
                .Invoke()[0]
                .ToString();

            return new Dictionary<string string ,> { { &quot;income&quot;, income } };
        }
    }
}
&quot;@</span>            
            
<span style="color: #0000ff">Add-Type</span> <span style="color: #000080">-ReferencedAssemblies</span> <span style="color: #ff4500">$ReferencedAssemblies</span> <span style="color: #000000">`
</span>    <span style="color: #000080">-OutputAssembly</span> <span style="color: #8a2be2">CalculateBudget.dll</span> <span style="color: #000000">`
</span>    <span style="color: #000080">-TypeDefinition</span> <span style="color: #ff4500">$powerShell</span>            
            
<span style="color: #0000ff">Write-Host</span> <span style="color: #000080">-fore</span> <span style="color: #8a2be2">green</span> <span style="color: #8b0000">&quot;Compiled DLL&quot;</span>            
            
<span style="color: #00008b">if</span><span style="color: #000000">(</span><span style="color: #ff4500">$?</span><span style="color: #000000">)</span> <span style="color: #000000">{</span>            
            
<span style="color: #8b0000">@&quot;
var owin = require('owin')

console.log('Starting long running operation...');
owin.worker(
    'CalculateBudget.dll',
    { revenue: 100, cost: 80 },
    function (error, result) {
        if (error) throw error;
        console.log('Result of long running operation: ', result);
    }
);

setInterval(function () {
    console.log('Node.js event loop is alive!')
}, 1000);
&quot;@</span> <span style="color: #a9a9a9">|</span>  <span style="color: #0000ff">Set-Content</span> <span style="color: #000080">-Encoding</span> <span style="color: #8a2be2">Ascii</span> <span style="color: #8a2be2">.\test.js</span>            
            
<span style="color: #0000ff">Write-Host</span> <span style="color: #000080">-fore</span> <span style="color: #8a2be2">green</span> <span style="color: #8b0000">&quot;Create JavaScript file&quot;</span>            
<span style="color: #0000ff">Write-Host</span> <span style="color: #000080">-fore</span> <span style="color: #8a2be2">green</span> <span style="color: #8b0000">&quot;Running nodejs&quot;</span>            
            
<span style="color: #0000ff">node</span> <span style="color: #8a2be2">.\test.js</span>            
            
<span style="color: #000000">}</span></pre>
<p>This opens interesting ways to experiment with Node, .NET and PowerShell. </p>
<h3>Download</h3>
<p>Here it is.&#160;&#160;&#160;&#160;&#160; <a href="https://skydrive.live.com/redir.aspx?cid=5dec3b62d9308943&amp;page=self&amp;resid=5DEC3B62D9308943%211552&amp;parid=5DEC3B62D9308943%211551&amp;authkey=%21&amp;Bpub=SDX.SkyDrive&amp;Bsrc=Share"><img src="https://p.sfx.ms/ftype/v4/Zip.png" /></a>&#160;<a href="https://skydrive.live.com/redir.aspx?cid=5dec3b62d9308943&amp;page=self&amp;resid=5DEC3B62D9308943%211552&amp;parid=5DEC3B62D9308943%211551&amp;authkey=%21&amp;Bpub=SDX.SkyDrive&amp;Bsrc=Share">Owinjs.zip</a></p>
<p>Enjoy!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dougfinke.com/blog/index.php/2013/02/26/how-to-run-powershell-from-node-js/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Using PowerShell to find all the years since you were born where the four digits were unique</title>
		<link>http://www.dougfinke.com/blog/index.php/2013/01/01/using-powershell-to-find-all-the-years-since-you-were-born-where-the-four-digits-were-unique/</link>
		<comments>http://www.dougfinke.com/blog/index.php/2013/01/01/using-powershell-to-find-all-the-years-since-you-were-born-where-the-four-digits-were-unique/#comments</comments>
		<pubDate>Tue, 01 Jan 2013 18:21:41 +0000</pubDate>
		<dc:creator>Doug Finke</dc:creator>
				<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[PowerShell for Developers]]></category>
		<category><![CDATA[PowerShell V3]]></category>

		<guid isPermaLink="false">http://www.dougfinke.com/blog/index.php/2013/01/01/using-powershell-to-find-all-the-years-since-you-were-born-where-the-four-digits-were-unique/</guid>
		<description><![CDATA[June Blender Rogers posted on Facebook: &#34;2013 will be the first year in my entire life where all four digits were unique.&#34; &#8212; Jackson Cahn, born 1988. The Question What would a PowerShell script look like that could figure out, from a range of years, each year where all four digits are unique? function Get-UniqueYear [...]]]></description>
				<content:encoded><![CDATA[<p><a href="http://www.facebook.com/juneblender">June Blender Rogers</a> posted on Facebook:</p>
<blockquote><p>&quot;2013 will be the first year in my entire life where all four digits were unique.&quot; &#8212; Jackson Cahn, born 1988.</p>
</blockquote>
<h3>The Question</h3>
<p>What would a PowerShell script look like that could figure out, from a range of years, each year where all four digits are unique?</p>
<pre class="PowerShellColorizedScript" style="height: 421px; width: 555px"><span style="color: #00008b">function</span> <span style="color: #8a2be2">Get-UniqueYear</span> <span style="color: #000000">{</span>            
    <span style="color: #00008b">param</span><span style="color: #000000">(</span>            
        <span style="color: #ff4500">$YearBorn</span><span style="color: #a9a9a9">=</span><span style="color: #800080">1987</span>            
    <span style="color: #000000">)</span>            
            
    <span style="color: #ff4500">$thisYear</span> <span style="color: #a9a9a9">=</span> <span style="color: #000000">(</span><span style="color: #0000ff">Get-Date</span><span style="color: #000000">)</span><span style="color: #a9a9a9">.</span><span style="color: #000000">Year</span>            
    <span style="color: #008080">[string]</span><span style="color: #ff4500">$targetYear</span> <span style="color: #a9a9a9">=</span> <span style="color: #ff4500">$null</span>            
            
    <span style="color: #00008b">foreach</span><span style="color: #000000">(</span><span style="color: #ff4500">$targetYear</span> <span style="color: #00008b">in</span> <span style="color: #ff4500">$YearBorn</span><span style="color: #a9a9a9">..</span><span style="color: #ff4500">$thisYear</span><span style="color: #000000">)</span> <span style="color: #000000">{</span>            
            
        <span style="color: #ff4500">$targetYearAsCharArray</span> <span style="color: #a9a9a9">=</span> <span style="color: #ff4500">$targetYear</span><span style="color: #a9a9a9">.</span><span style="color: #000000">ToCharArray</span><span style="color: #000000">(</span><span style="color: #000000">)</span>            
            
        <span style="color: #ff4500">$unique</span> <span style="color: #a9a9a9">=</span> <span style="color: #ff4500">$true</span>            
        <span style="color: #00008b">foreach</span><span style="color: #000000">(</span><span style="color: #ff4500">$digit</span> <span style="color: #00008b">in</span> <span style="color: #ff4500">$targetYearAsCharArray</span><span style="color: #000000">)</span> <span style="color: #000000">{</span>            
            <span style="color: #00008b">if</span><span style="color: #000000">(</span> <span style="color: #000000">(</span><span style="color: #ff4500">$targetYearAsCharArray</span> <span style="color: #a9a9a9">-eq</span> <span style="color: #ff4500">$digit</span><span style="color: #000000">)</span><span style="color: #a9a9a9">.</span><span style="color: #000000">Count</span> <span style="color: #a9a9a9">-ge</span> <span style="color: #800080">2</span> <span style="color: #000000">)</span> <span style="color: #000000">{</span>            
                <span style="color: #ff4500">$unique</span> <span style="color: #a9a9a9">=</span> <span style="color: #ff4500">$false</span>                            
            <span style="color: #000000">}</span>            
        <span style="color: #000000">}</span>            
            
        <span style="color: #00008b">if</span><span style="color: #000000">(</span><span style="color: #ff4500">$unique</span><span style="color: #000000">)</span> <span style="color: #000000">{</span><span style="color: #ff4500">$targetYear</span><span style="color: #000000">}</span>            
    <span style="color: #000000">}</span>            
<span style="color: #000000">}</span></pre>
<h3>Challenge</h3>
<ul>
<li>How would you improve this?</li>
<li>How would you test it with <a href="https://github.com/pester/Pester">Pester</a>? (Try my <a href="https://github.com/dfinke/IsePester">IsePester addon</a>)</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.dougfinke.com/blog/index.php/2013/01/01/using-powershell-to-find-all-the-years-since-you-were-born-where-the-four-digits-were-unique/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>Use PowerShell to find the free space on the volume behind an SMB file share</title>
		<link>http://www.dougfinke.com/blog/index.php/2012/12/25/use-powershell-to-find-the-free-space-on-the-volume-behind-an-smb-file-share/</link>
		<comments>http://www.dougfinke.com/blog/index.php/2012/12/25/use-powershell-to-find-the-free-space-on-the-volume-behind-an-smb-file-share/#comments</comments>
		<pubDate>Wed, 26 Dec 2012 03:19:39 +0000</pubDate>
		<dc:creator>Doug Finke</dc:creator>
				<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[PowerShell V3]]></category>
		<category><![CDATA[Window Server 2012]]></category>
		<category><![CDATA[Windows 8]]></category>

		<guid isPermaLink="false">http://www.dougfinke.com/blog/index.php/2012/12/25/use-powershell-to-find-the-free-space-on-the-volume-behind-an-smb-file-share/</guid>
		<description><![CDATA[Jose Barreto blogged the details HERE. His original script is fine and works. I refactored his script this way. I prefer this style, it feels more readable. Using features of PowerShell v3 makes it easier to write scripts more concisely. Jose used PowerShell v2 techniques that still work but are more verbose and bulky. What [...]]]></description>
				<content:encoded><![CDATA[<p>Jose Barreto blogged the details <a href="http://blogs.technet.com/b/josebda/archive/2012/11/19/windows-server-2012-file-server-tip-use-powershell-to-find-the-free-space-on-the-volume-behind-an-smb-file-share.aspx?utm_source=twitterfeed&amp;utm_medium=twitter">HERE</a>.</p>
<p>His original script is fine and works.</p>
<p>I refactored his script this way. I prefer this style, it feels more readable. Using features of PowerShell v3 makes it easier to write scripts more concisely. Jose used PowerShell v2 techniques that still work but are more verbose and bulky.</p>
<p>What do you think?</p>
<h3>Refactored Version</h3>
<pre class="PowerShellColorizedScript" style="height: 258px; width: 550px;"><span style="color: #ff4500;">$CimSession </span><span style="color: #a9a9a9;">=</span> <span style="color: #8b0000;">"."</span>            

<span style="color: #00008b;">ForEach</span><span style="color: #000000;">(</span><span style="color: #ff4500;">$item</span> <span style="color: #00008b;">in</span> <span style="color: #0000ff;">Get-SmbShare</span> <span style="color: #000080;">-CimSession</span> <span style="color: #ff4500;">$CimSession</span> <span style="color: #a9a9a9;">|</span> <span style="color: #0000ff;">Where</span> <span style="color: #8a2be2;">Volume</span><span style="color: #000000;">)</span> <span style="color: #000000;">{</span>            

    <span style="color: #ff4500;">$volume</span> <span style="color: #a9a9a9;">=</span> <span style="color: #0000ff;">Get-Volume</span> <span style="color: #000080;">-CimSession</span> <span style="color: #ff4500;">$CimSession </span><span style="color: #000080;">-Id</span> <span style="color: #ff4500;">$item</span><span style="color: #a9a9a9;">.</span><span style="color: #000000;">Volume</span>            

    <span style="color: #008080;">[PSCustomObject]</span> <span style="color: #000000;">@{</span>            
        <span style="color: #000000;">Share</span>     <span style="color: #a9a9a9;">=</span> <span style="color: #ff4500;">$item</span><span style="color: #a9a9a9;">.</span><span style="color: #000000;">Name</span>            
        <span style="color: #000000;">Path</span>      <span style="color: #a9a9a9;">=</span> <span style="color: #ff4500;">$item</span><span style="color: #a9a9a9;">.</span><span style="color: #000000;">Path</span>            
        <span style="color: #000000;">Size</span>      <span style="color: #a9a9a9;">=</span> <span style="color: #ff4500;">$volume</span><span style="color: #a9a9a9;">.</span><span style="color: #000000;">Size</span>            
        <span style="color: #000000;">Remaining</span> <span style="color: #a9a9a9;">=</span> <span style="color: #ff4500;">$volume</span><span style="color: #a9a9a9;">.</span><span style="color: #000000;">SizeRemaining</span>             
    <span style="color: #000000;">}</span>            
<span style="color: #000000;">}</span></pre>
<h3>Original</h3>
<pre class="PowerShellColorizedScript"><span style="color: #0000ff;">Get-SmbShare</span> <span style="color: #000080;">-CimSession</span> <span style="color: #8a2be2;">FST2-FS2</span> <span style="color: #a9a9a9;">|</span>             
    <span style="color: #0000ff;">?</span> <span style="color: #8a2be2;">Volume</span>  <span style="color: #000080;">-ne</span> <span style="color: #ff4500;">$null</span> <span style="color: #a9a9a9;">|</span>             
    <span style="color: #0000ff;">%</span> <span style="color: #000000;">{</span>             
        <span style="color: #ff4500;">$R</span> <span style="color: #a9a9a9;">=</span> <span style="color: #8b0000;">""</span> <span style="color: #a9a9a9;">|</span> <span style="color: #0000ff;">Select</span> <span style="color: #8a2be2;">Share</span><span style="color: #a9a9a9;">,</span> <span style="color: #8a2be2;">Path</span><span style="color: #a9a9a9;">,</span> <span style="color: #8a2be2;">Size</span><span style="color: #a9a9a9;">,</span> <span style="color: #8a2be2;">Free</span>            
        <span style="color: #ff4500;">$R</span><span style="color: #a9a9a9;">.</span><span style="color: #000000;">Share</span><span style="color: #a9a9a9;">=</span><span style="color: #ff4500;">$_</span><span style="color: #a9a9a9;">.</span><span style="color: #000000;">Name</span><span style="color: #000000;">;</span> <span style="color: #ff4500;">$R</span><span style="color: #a9a9a9;">.</span><span style="color: #000000;">Path</span><span style="color: #a9a9a9;">=</span><span style="color: #ff4500;">$_</span><span style="color: #a9a9a9;">.</span><span style="color: #000000;">Path</span>            
        <span style="color: #0000ff;">Get-Volume</span> <span style="color: #000080;">-CimSession</span> <span style="color: #8a2be2;">FST2-FS2</span> <span style="color: #000080;">-Id</span> <span style="color: #ff4500;">$_</span><span style="color: #a9a9a9;">.</span><span style="color: #000000;">Volume</span> <span style="color: #a9a9a9;">|</span>             
        <span style="color: #0000ff;">%</span> <span style="color: #000000;">{</span>             
            <span style="color: #ff4500;">$R</span><span style="color: #a9a9a9;">.</span><span style="color: #000000;">Size</span><span style="color: #a9a9a9;">=</span><span style="color: #ff4500;">$_</span><span style="color: #a9a9a9;">.</span><span style="color: #000000;">Size</span><span style="color: #000000;">;</span> <span style="color: #ff4500;">$R</span><span style="color: #a9a9a9;">.</span><span style="color: #000000;">Free</span><span style="color: #a9a9a9;">=</span><span style="color: #ff4500;">$_</span><span style="color: #a9a9a9;">.</span><span style="color: #000000;">SizeRemaining</span><span style="color: #000000;">;</span> <span style="color: #ff4500;">$R</span> <span style="color: #a9a9a9;">|</span> <span style="color: #0000ff;">FL</span> <span style="color: #000000;">}</span>            
        <span style="color: #000000;">}</span></pre>
]]></content:encoded>
			<wfw:commentRss>http://www.dougfinke.com/blog/index.php/2012/12/25/use-powershell-to-find-the-free-space-on-the-volume-behind-an-smb-file-share/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Learn one PowerShell command</title>
		<link>http://www.dougfinke.com/blog/index.php/2012/11/10/learn-one-powershell-command/</link>
		<comments>http://www.dougfinke.com/blog/index.php/2012/11/10/learn-one-powershell-command/#comments</comments>
		<pubDate>Sat, 10 Nov 2012 18:36:37 +0000</pubDate>
		<dc:creator>Doug Finke</dc:creator>
				<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[Perl]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[PowerShell for Developers]]></category>
		<category><![CDATA[PowerShell V3]]></category>
		<category><![CDATA[UNIX]]></category>

		<guid isPermaLink="false">http://www.dougfinke.com/blog/index.php/2012/11/10/learn-one-powershell-command/</guid>
		<description><![CDATA[John Cook has an interesting blog post, “Learn one Perl command”. He highlights text replacement, using the Unix command sed. But, others commented and did him one better suggesting he use a perl –pi. PowerShell doesn’t have this out of the box. So let’s write a module. Follow along, grab the PowerShell module here. The [...]]]></description>
				<content:encoded><![CDATA[<p>John Cook has an interesting blog post, “<a href="http://www.johndcook.com/blog/2012/11/09/learn-one-perl-command/">Learn one Perl command</a>”. He highlights text replacement, using the Unix command <em><strong>sed. </strong></em>But, others commented and did him one better suggesting he use a <strong><em>perl –pi</em></strong>.</p>
<p>PowerShell doesn’t have this out of the box. So let’s write a module.</p>
<blockquote><p>Follow along, grab the <a href="http://goo.gl/QlR2z">PowerShell module here</a>.</p>
</blockquote>
<p>The PowerShell <em><strong>Invoke-Replace</strong></em> command lets you replace text:</p>
<ul>
<li>In place, for any or all files in the current directory, based on a file pattern match </li>
<li>Using simple or regular expression matching </li>
<li>Plus, it can backup the target file, to the same name with an extension you supply like <strong><em>.bak</em></strong>, before editing it </li>
</ul>
<h3>The PowerShell Module</h3>
<p>Here are <em><strong>Invoke-Replace</strong></em> and <em><strong>Backup-File</strong></em>.</p>
<pre class="PowerShellColorizedScript" style="height: 631px; width: 493px"><span style="color: #00008b">function</span> <span style="color: #8a2be2">Invoke-Replace</span> <span style="color: #000000">{</span>            
    <span style="color: #00008b">param</span><span style="color: #000000">(</span>            
        <span style="color: #ff4500">$Match</span><span style="color: #a9a9a9">,</span>            
        <span style="color: #ff4500">$Replace</span><span style="color: #a9a9a9">,</span>            
        <span style="color: #ff4500">$Include</span><span style="color: #a9a9a9">=</span><span style="color: #8b0000">&quot;*&quot;</span><span style="color: #a9a9a9">,</span>            
        <span style="color: #ff4500">$BackupExtension</span>            
    <span style="color: #000000">)</span>                
            
    <span style="color: #ff4500">$files</span> <span style="color: #a9a9a9">=</span> <span style="color: #0000ff">Get-ChildItem</span> <span style="color: #8a2be2">.</span> <span style="color: #ff4500">$Include</span>            
    <span style="color: #00008b">ForEach</span><span style="color: #000000">(</span><span style="color: #ff4500">$file</span> <span style="color: #00008b">in</span> <span style="color: #ff4500">$files</span><span style="color: #000000">)</span> <span style="color: #000000">{</span>            
            
      <span style="color: #0000ff">Backup-File</span> <span style="color: #ff4500">$file</span> <span style="color: #ff4500">$BackupExtension</span>            
      <span style="color: #ff4500">$targetFile</span> <span style="color: #a9a9a9">=</span> <span style="color: #ff4500">$file</span><span style="color: #a9a9a9">.</span><span style="color: #000000">FullName</span>            
                  
      <span style="color: #008080">[IO.File]</span><span style="color: #a9a9a9">::</span><span style="color: #000000">ReadLines</span><span style="color: #000000">(</span><span style="color: #ff4500">$targetFile</span><span style="color: #000000">)</span> <span style="color: #a9a9a9">-replace</span> <span style="color: #ff4500">$Match</span><span style="color: #a9a9a9">,</span> <span style="color: #ff4500">$Replace</span> <span style="color: #a9a9a9">|</span>             
        <span style="color: #0000ff">Set-Content</span> <span style="color: #ff4500">$targetFile</span>            
    <span style="color: #000000">}</span>            
<span style="color: #000000">}</span>            
            
<span style="color: #00008b">function</span> <span style="color: #8a2be2">Backup-File</span> <span style="color: #000000">{</span>            
    <span style="color: #00008b">param</span><span style="color: #000000">(</span>                    
        <span style="color: #ff4500">$File</span><span style="color: #a9a9a9">,</span>            
        <span style="color: #ff4500">$BackupExtension</span>            
    <span style="color: #000000">)</span>            
            
    <span style="color: #00008b">if</span><span style="color: #000000">(</span><span style="color: #a9a9a9">!</span><span style="color: #ff4500">$BackupExtension</span><span style="color: #000000">)</span> <span style="color: #000000">{</span> <span style="color: #00008b">return</span> <span style="color: #000000">}</span>            
            
    <span style="color: #ff4500">$path</span> <span style="color: #a9a9a9">=</span> <span style="color: #ff4500">$File</span><span style="color: #a9a9a9">.</span><span style="color: #000000">FullName</span>            
    <span style="color: #ff4500">$destination</span> <span style="color: #a9a9a9">=</span> <span style="color: #ff4500">$path</span> <span style="color: #a9a9a9">+</span> <span style="color: #ff4500">$BackupExtension</span>            
            
    <span style="color: #0000ff">Copy-Item</span> <span style="color: #000080">-Path</span> <span style="color: #ff4500">$path</span> <span style="color: #000080">-Destination</span> <span style="color: #ff4500">$destination</span>            
<span style="color: #000000">}</span>            
            </pre>
<h3>How to Use <em><strong>Invoke-Replace</strong></em></h3>
<p>In the <em><strong>Tests</strong></em> <a href="http://goo.gl/QlR2z">subdirectory</a> there is <em><strong>TestInvokeReplace.ps1</strong></em> which tries out the <em><strong>Invoke-Replace</strong></em>. </p>
<p>For example, the following removes commas that immediately follow a digit, for all files in the current directory that have the file extension <strong><em>.txt</em></strong>.</p>
<pre class="PowerShellColorizedScript" style="height: 25px; width: 251px"><span style="color: #0000ff">Invoke-Replace</span> <span style="color: #8b0000">&quot;(?&lt;=\d),&quot;</span> <span style="color: #8b0000">&quot;&quot;</span> <span style="color: #8a2be2">*.txt</span></pre>
<h3>Here’s how to do a Backup</h3>
<p>Adding <strong><em>.bak</em></strong> as a final parameter instructs <em><strong>Invoke-Replace</strong></em> to copy the source file to the same named file and add <em><strong>.bak</strong></em> as the extension.</p>
<pre class="PowerShellColorizedScript" style="height: 26px; width: 279px"><span style="color: #0000ff">Invoke-Replace</span> <span style="color: #8b0000">&quot;(?&lt;=\d),&quot;</span> <span style="color: #8b0000">&quot;&quot;</span> <span style="color: #8a2be2">*.txt</span> <span style="color: #8a2be2">.bak</span></pre>
<h3>Using Parameter Names</h3>
<p>Here is what <em><strong>Invoke-Replace</strong></em> looks like with the parameter names specified.</p>
<pre class="PowerShellColorizedScript" style="height: 43px; width: 368px"><span style="color: #0000ff">Invoke-Replace</span> <span style="color: #000080">-Match</span> <span style="color: #8b0000">&quot;(?&lt;=\d),&quot;</span> <span style="color: #000080">-Replace</span> <span style="color: #8b0000">&quot;&quot;</span> <span style="color: #000000">`
</span>    <span style="color: #000080">-Include</span> <span style="color: #8a2be2">*.txt</span> <span style="color: #000080">-BackupExtension</span> <span style="color: #8a2be2">.bak</span></pre>
<h3>Learning Perl is a big commitment</h3>
<p>Or any other scripting or programming language for that matter. What I find interesting though, is these other more established environments have been through the mine fields and collected some terrific experiences over the decades.</p>
<p>Transcoding their scripting experiences often yield very usable solutions.</p>
<h3>Check out the Script</h3>
<p>Here is the <em><strong>InvokeReplace</strong></em> module <a href="https://github.com/dfinke/PowerShellTools">https://github.com/dfinke/PowerShellTools</a>. I keep several others here <a href="https://github.com/dfinke">https://github.com/dfinke</a> including the scripts from my book “<a href="http://www.amazon.com/Windows-PowerShell-Developers-Douglas-Finke/dp/1449322700">PowerShell for Developers</a>”.</p>
<p>They are open source and ready to be forked and improved.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dougfinke.com/blog/index.php/2012/11/10/learn-one-powershell-command/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>I&#8217;ll be presenting on PowerShell at the Philly Code Camp</title>
		<link>http://www.dougfinke.com/blog/index.php/2012/11/08/ill-be-presenting-on-powershell-at-the-philly-code-camp/</link>
		<comments>http://www.dougfinke.com/blog/index.php/2012/11/08/ill-be-presenting-on-powershell-at-the-philly-code-camp/#comments</comments>
		<pubDate>Fri, 09 Nov 2012 00:57:13 +0000</pubDate>
		<dc:creator>Doug Finke</dc:creator>
				<category><![CDATA[Code Camp]]></category>
		<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[PowerShell for Developers]]></category>

		<guid isPermaLink="false">http://www.dougfinke.com/blog/index.php/2012/11/08/ill-be-presenting-on-powershell-at-the-philly-code-camp/</guid>
		<description><![CDATA[Saturday, November 17 It is being held at the Penn State campus in Abington, PA. I’ll be giving away copies of my book “PowerShell for Developers”. Stop in and say hello.]]></description>
				<content:encoded><![CDATA[<h3><a href="http://phillydotnet.org/camps/2012-2/#more-1049">Saturday, November 17</a></h3>
<p>It is being held at the Penn State campus in Abington, PA.</p>
<p>I’ll be giving away copies of my book “PowerShell for Developers”.</p>
<p>Stop in and say hello.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dougfinke.com/blog/index.php/2012/11/08/ill-be-presenting-on-powershell-at-the-philly-code-camp/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Building GUI Applications in PowerShell</title>
		<link>http://www.dougfinke.com/blog/index.php/2012/11/07/building-gui-applications-in-powershell/</link>
		<comments>http://www.dougfinke.com/blog/index.php/2012/11/07/building-gui-applications-in-powershell/#comments</comments>
		<pubDate>Thu, 08 Nov 2012 03:27:13 +0000</pubDate>
		<dc:creator>Doug Finke</dc:creator>
				<category><![CDATA[Dr. Dobb's]]></category>
		<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[O'Reilly]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[PowerShell for Developers]]></category>

		<guid isPermaLink="false">http://www.dougfinke.com/blog/index.php/2012/11/07/building-gui-applications-in-powershell/</guid>
		<description><![CDATA[Excerpted in Dr. Dobb’s This chapter from my book, “PowerShell for Developers”,&#160; has been excerpted in Dr. Dobb’s. The book also covers Other PowerShell v3 features and more: Slice and dice Text, XML, CSV, and JSON effortlessly Embed PowerShell to provide scripting abilities for your C# apps Create GUI applications five to ten times faster [...]]]></description>
				<content:encoded><![CDATA[<h3>Excerpted in Dr. Dobb’s</h3>
<p>This chapter from my book, “<a href="http://goo.gl/EO36X">PowerShell for Developers</a>”,&#160; has been <a href="http://goo.gl/E1VJw">excerpted in Dr. Dobb’s</a>.</p>
<h3>The book also covers </h3>
<p>Other PowerShell v3 features and more:</p>
<ul>
<li>Slice and dice Text, XML, CSV, and JSON effortlessly </li>
<li><a href="http://goo.gl/EO36X"><img style="float: left; margin: 8px 35px 0px 0px; display: inline" align="left" src="http://www.dougfinke.com/blog/wp-content/uploads/2012/07/FrontCover.png" /></a>Embed PowerShell to provide scripting abilities for your C# apps </li>
<li>Create GUI applications five to ten times faster with less code </li>
<li>Leverage PowerShell’s capabilities to work with the Internet </li>
<li>Interact with DLLs and create objects, automatically display properties, and call methods in live interactive sessions </li>
<li>Build domain-specific languages (DSLs) and vocabularies to express solutions more clearly </li>
<li>Work with Microsoft Office via the Component Object Model (COM) </li>
<li>Discover PowerShell v3 features included with Windows 8 and Windows Server 2012</li>
</ul>
<h3>GitHub: Source Code and Examples From The Book</h3>
<p><a href="https://github.com/dfinke/powershell-for-developers">This repository</a> contains the latest definitive bug fixed source code for the examples.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dougfinke.com/blog/index.php/2012/11/07/building-gui-applications-in-powershell/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Honorary PowerShell Scripting Guy</title>
		<link>http://www.dougfinke.com/blog/index.php/2012/11/04/honorary-powershell-scripting-guy/</link>
		<comments>http://www.dougfinke.com/blog/index.php/2012/11/04/honorary-powershell-scripting-guy/#comments</comments>
		<pubDate>Sun, 04 Nov 2012 12:46:03 +0000</pubDate>
		<dc:creator>Doug Finke</dc:creator>
				<category><![CDATA[Hey, Scripting Guy]]></category>
		<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[PowerShell]]></category>

		<guid isPermaLink="false">http://www.dougfinke.com/blog/index.php/2012/11/04/honorary-powershell-scripting-guy/</guid>
		<description><![CDATA[Microsoft Scripting Guy, Ed Wilson, announced the official Honorary Scripting Guys! What does it take to become an official Honorary Scripting Guy? It takes an extreme commitment to the scripting community, a remarkable dedication helping to spread the good word about Windows PowerShell, and a relentless pursuit of excellence in producing exceptional content. Thank you [...]]]></description>
				<content:encoded><![CDATA[<p>Microsoft Scripting Guy, Ed Wilson, <a href="http://goo.gl/fE74m">announced the official Honorary Scripting Guys</a>!</p>
<blockquote><p>What does it take to become an official Honorary Scripting Guy?<em> </em>It takes an extreme commitment to the scripting community, a remarkable dedication helping to spread the good word about Windows PowerShell, and a relentless pursuit of excellence in producing exceptional content.</p>
</blockquote>
<p>Thank you very much Ed. It’s an honor to be selected and be a part of a great group of contributors.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dougfinke.com/blog/index.php/2012/11/04/honorary-powershell-scripting-guy/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
