<?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>PowerShell.cz</title>
	<atom:link href="http://powershell.cz/feed/" rel="self" type="application/rss+xml" />
	<link>http://powershell.cz</link>
	<description>Get-World &#124; ConvertTo-PowerShell</description>
	<lastBuildDate>Sat, 07 Jan 2012 19:21:00 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=</generator>
		<item>
		<title>Auto complete for about_* topics</title>
		<link>http://powershell.cz/2012/01/07/auto-complete-for-about_-topics/</link>
		<comments>http://powershell.cz/2012/01/07/auto-complete-for-about_-topics/#comments</comments>
		<pubDate>Sat, 07 Jan 2012 19:21:00 +0000</pubDate>
		<dc:creator>makovec</dc:creator>
				<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[Help]]></category>

		<guid isPermaLink="false">http://powershell.cz/?p=256</guid>
		<description><![CDATA[Today I was heavily working with PowerShell help system. And was tired to call it using Get-Help cmdlet. So I created small function which I put to my profile: function Show-HelpAboutFunction { $topics = Get-Help about_* foreach ($t in $topics) { $tn = $t.Name -replace 'about_', 'abt-' $text = "function global:$($tn) { Get-Help $($t.Name) }" <a href="http://powershell.cz/2012/01/07/auto-complete-for-about_-topics/" class="more-link">More &#62;</a>]]></description>
			<content:encoded><![CDATA[<p>Today I was heavily working with PowerShell help system. And was tired to call it using Get-Help cmdlet. So I created small function which I put to my profile:</p>
<pre><span style="color: #0000FF;">function</span><span style="color: #000000;"> </span><span style="color: #5F9EA0;">Show-HelpAboutFunction</span><span style="color: #000000;">
{
    </span><span style="color: #800080;">$topics</span><span style="color: #000000;"> </span><span style="color: #FF0000;">=</span><span style="color: #000000;"> </span><span style="color: #5F9EA0; font-weight: bold;">Get-Help</span><span style="color: #000000;"> about_</span><span style="color: #800000;">*</span><span style="color: #000000;"> 

    </span><span style="color: #0000FF;">foreach</span><span style="color: #000000;"> (</span><span style="color: #800080;">$t</span><span style="color: #000000;"> </span><span style="color: #0000FF;">in</span><span style="color: #000000;"> </span><span style="color: #800080;">$topics</span><span style="color: #000000;">)
    {
        </span><span style="color: #800080;">$tn</span><span style="color: #000000;"> </span><span style="color: #FF0000;">=</span><span style="color: #000000;"> </span><span style="color: #800080;">$t</span><span style="color: #000000;">.Name </span><span style="color: #FF0000;">-replace</span><span style="color: #000000;"> </span><span style="color: #800000;">'</span><span style="color: #800000;">about_</span><span style="color: #800000;">'</span><span style="color: #000000;">, </span><span style="color: #800000;">'</span><span style="color: #800000;">abt-</span><span style="color: #800000;">'</span><span style="color: #000000;">
        </span><span style="color: #800080;">$text</span><span style="color: #000000;"> </span><span style="color: #FF0000;">=</span><span style="color: #000000;"> </span><span style="color: #800000;">"</span><span style="color: #800000;">function global:$($tn) { Get-Help $($t.Name) }</span><span style="color: #800000;">"</span><span style="color: #000000;">

        </span><span style="color: #5F9EA0; font-weight: bold;">Invoke-Expression</span><span style="color: #000000;"> </span><span style="color: #800000;">"</span><span style="color: #800000;">$text</span><span style="color: #800000;">"</span><span style="color: #000000;">
    }
}</span></pre>
<p>So when in console I can write: <strong>abt-func&lt;Tab&gt;</strong> and can circulate help topics till have the one I need. I know that for some topics is better to write Get-Help with partial help topic name, but in some cases I like my solution more.</p>
<p>Note: I know that abt is not approved verb <img src='http://powershell.cz/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://powershell.cz/2012/01/07/auto-complete-for-about_-topics/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ISE: List variables in active Script Pane</title>
		<link>http://powershell.cz/2012/01/01/ise-list-variables-in-active-script-pane/</link>
		<comments>http://powershell.cz/2012/01/01/ise-list-variables-in-active-script-pane/#comments</comments>
		<pubDate>Sun, 01 Jan 2012 17:21:11 +0000</pubDate>
		<dc:creator>makovec</dc:creator>
				<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[ISE]]></category>

		<guid isPermaLink="false">http://powershell.cz/?p=243</guid>
		<description><![CDATA[I was working in ISE pretty much during last two days (oh yes, was nice end of 2011 and beginning of 2012). During script creation I was checking values of variables frequently. Wouldn&#8217;t be nice to see variables value and not just write it&#8217;s name to Command Pane? So I came with another menu Add-on <a href="http://powershell.cz/2012/01/01/ise-list-variables-in-active-script-pane/" class="more-link">More &#62;</a>]]></description>
			<content:encoded><![CDATA[<p>I was working in ISE pretty much during last two days (oh yes, was nice end of 2011 and beginning of 2012). During script creation I was checking values of variables frequently. Wouldn&#8217;t be nice to see variables value and not just write it&#8217;s name to Command Pane? So I came with another menu Add-on command.</p>
<pre><span style="color: #0000FF;">function</span><span style="color: #000000;"> </span><span style="color: #5F9EA0;">GetValues</span><span style="color: #000000;">
{
    </span><span style="color: #800080;">$content</span><span style="color: #000000;"> </span><span style="color: #FF0000;">=</span><span style="color: #000000;"> </span><span style="color: #800080;">$psISE</span><span style="color: #000000;">.CurrentFile.Editor.Text
    </span><span style="color: #800080;">$tokens</span><span style="color: #000000;"> </span><span style="color: #FF0000;">=</span><span style="color: #000000;"> [</span><span style="color: #008080;">System.Management.Automation.PsParser</span><span style="color: #000000;">]::</span><span style="color: #8B4513;">Tokenize</span><span style="color: #000000;">(</span><span style="color: #800080;">$content</span><span style="color: #000000;">, [</span><span style="color: #008080;">ref</span><span style="color: #000000;">] </span><span style="color: #800080;">$null</span><span style="color: #000000;">) |? {</span><span style="color: #800080;">$_</span><span style="color: #000000;">.Type </span><span style="color: #FF0000;">-eq</span><span style="color: #000000;"> </span><span style="color: #800000;">'</span><span style="color: #800000;">Variable</span><span style="color: #800000;">'</span><span style="color: #000000;">} | </span><span style="color: #5F9EA0; font-weight: bold;">Sort</span><span style="color: #000000;"> </span><span style="color: #800000;">Content</span><span style="color: #000000;"> </span><span style="color: #5F9EA0; font-style: italic;">-Unique</span><span style="color: #000000;">

    </span><span style="color: #0000FF;">foreach</span><span style="color: #000000;"> (</span><span style="color: #800080;">$t</span><span style="color: #000000;"> </span><span style="color: #0000FF;">in</span><span style="color: #000000;"> </span><span style="color: #800080;">$tokens</span><span style="color: #000000;">)
    {
        </span><span style="color: #800080;">$prop</span><span style="color: #000000;"> </span><span style="color: #FF0000;">=</span><span style="color: #000000;"> @{
            Name </span><span style="color: #FF0000;">=</span><span style="color: #000000;"> </span><span style="color: #800080;">$t</span><span style="color: #000000;">.Content
            Value </span><span style="color: #FF0000;">=</span><span style="color: #000000;"> </span><span style="color: #5F9EA0; font-weight: bold;">Get-Variable</span><span style="color: #000000;"> </span><span style="color: #5F9EA0; font-style: italic;">-Name</span><span style="color: #000000;"> $(</span><span style="color: #800080;">$t</span><span style="color: #000000;">.Content) </span><span style="color: #5F9EA0; font-style: italic;">-ValueOnly</span><span style="color: #000000;"> </span><span style="color: #5F9EA0; font-style: italic;">-ErrorAction</span><span style="color: #000000;"> </span><span style="color: #800000;">SilentlyContinue</span><span style="color: #000000;">
        }

        </span><span style="color: #5F9EA0; font-weight: bold;">New-Object</span><span style="color: #000000;"> </span><span style="color: #5F9EA0; font-style: italic;">-TypeName</span><span style="color: #000000;"> </span><span style="color: #800000;">PSObject</span><span style="color: #000000;"> </span><span style="color: #5F9EA0; font-style: italic;">-Property</span><span style="color: #000000;"> </span><span style="color: #800080;">$prop</span><span style="color: #000000;"> | </span><span style="color: #5F9EA0; font-weight: bold;">Select</span><span style="color: #000000;"> Name, </span><span style="color: #800000;">Value</span><span style="color: #000000;">
    }
}

</span><span style="color: #800080;">$psISE</span><span style="color: #000000;">.CurrentPowerShellTab.AddOnsMenu.Submenus.Add(</span><span style="color: #800000;">'</span><span style="color: #800000;">Show values</span><span style="color: #800000;">'</span><span style="color: #000000;">,{</span><span style="color: #5F9EA0;">GetValues</span><span style="color: #000000;">},</span><span style="color: #800000;">'</span><span style="color: #800000;">CTRL+SHIFT+V</span><span style="color: #800000;">'</span><span style="color: #000000;">) | </span><span style="color: #5F9EA0; font-weight: bold;">Out-Null</span></pre>
<p>When you work with any script, you can run it and will see all actual script variables in <em>Output Pane</em>.</p>
<p><img class="alignnone" title="Variables in current script" src="http://www.powershell.cz/images/ISE-get-values/ISE_GetValues.jpg" alt="Variables in current script" width="710" height="568" /></p>
<p>Using Tokenizer API I received all variables from current script and created new object with variable name and value. Then it&#8217;s send to output. I am thinking about some graphical output (WPF or ShowUI) or just to Out-GridView. There are also some another points to update but for my current needs it&#8217;s OK.</p>
]]></content:encoded>
			<wfw:commentRss>http://powershell.cz/2012/01/01/ise-list-variables-in-active-script-pane/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ISE: Run current line without selecting, AKA v3 feature</title>
		<link>http://powershell.cz/2012/01/01/ise-run-current-line-without-selecting-aka-v3-feature/</link>
		<comments>http://powershell.cz/2012/01/01/ise-run-current-line-without-selecting-aka-v3-feature/#comments</comments>
		<pubDate>Sun, 01 Jan 2012 13:19:42 +0000</pubDate>
		<dc:creator>makovec</dc:creator>
				<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[ISE]]></category>

		<guid isPermaLink="false">http://powershell.cz/?p=226</guid>
		<description><![CDATA[I like one of new PowerShell v3 features. When you are in ISE and want to run current line, just press F8, it&#8217;s no more necessary to select the line and then use Run Selection (F8). I&#8217;d like to have it in v2 also so I created another quick function: function RunLine { $editor = <a href="http://powershell.cz/2012/01/01/ise-run-current-line-without-selecting-aka-v3-feature/" class="more-link">More &#62;</a>]]></description>
			<content:encoded><![CDATA[<p>I like one of new PowerShell v3 features. When you are in ISE and want to run current line, just press F8, it&#8217;s no more necessary to select the line and then use <em>Run Selection (F8)</em>. I&#8217;d like to have it in v2 also so I created another quick function:</p>
<pre><span style="color: #0000FF;">function</span><span style="color: #000000;"> </span><span style="color: #5F9EA0;">RunLine</span><span style="color: #000000;">
{
    </span><span style="color: #800080;">$editor</span><span style="color: #000000;"> </span><span style="color: #FF0000;">=</span><span style="color: #000000;"> </span><span style="color: #800080;">$psISE</span><span style="color: #000000;">.CurrentFile.Editor
    </span><span style="color: #800080;">$currentLine</span><span style="color: #000000;"> </span><span style="color: #FF0000;">=</span><span style="color: #000000;"> </span><span style="color: #800080;">$editor</span><span style="color: #000000;">.CaretLine
    </span><span style="color: #800080;">$currentLineLength</span><span style="color: #000000;"> </span><span style="color: #FF0000;">=</span><span style="color: #000000;"> </span><span style="color: #800080;">$editor</span><span style="color: #000000;">.GetLineLength(</span><span style="color: #800080;">$currentLine</span><span style="color: #000000;">)
    </span><span style="color: #800080;">$currentPosition</span><span style="color: #000000;"> </span><span style="color: #FF0000;">=</span><span style="color: #000000;"> </span><span style="color: #800080;">$editor</span><span style="color: #000000;">.CaretColumn

    </span><span style="color: #800080;">$psISE</span><span style="color: #000000;">.CurrentFile.Editor.Select(
        </span><span style="color: #800080;">$currentLine</span><span style="color: #000000;">, </span><span style="color: #000000;">1</span><span style="color: #000000;">,
        </span><span style="color: #800080;">$currentLine</span><span style="color: #000000;">, </span><span style="color: #800080;">$currentLineLength</span><span style="color: #000000;"> </span><span style="color: #FF0000;">+</span><span style="color: #000000;"> </span><span style="color: #000000;">1</span><span style="color: #000000;">
    )

    </span><span style="color: #800000;">"</span><span style="color: #800000;">Running &gt;&gt; $($psISE.CurrentFile.Editor.SelectedText)</span><span style="color: #800000;">"</span><span style="color: #000000;">
    </span><span style="color: #5F9EA0; font-weight: bold;">Invoke-Expression</span><span style="color: #000000;"> </span><span style="color: #800080;">$psISE</span><span style="color: #000000;">.CurrentFile.Editor.SelectedText

    </span><span style="color: #800080;">$psISE</span><span style="color: #000000;">.CurrentFile.Editor.Select(
        </span><span style="color: #800080;">$currentLine</span><span style="color: #000000;">, </span><span style="color: #800080;">$currentPosition</span><span style="color: #000000;">,
        </span><span style="color: #800080;">$currentLine</span><span style="color: #000000;">, </span><span style="color: #800080;">$currentPosition</span><span style="color: #000000;">
    )
}

</span><span style="color: #800080;">$makovecRoot</span><span style="color: #000000;"> </span><span style="color: #FF0000;">=</span><span style="color: #000000;"> </span><span style="color: #800080;">$psISE</span><span style="color: #000000;">.CurrentPowerShellTab.AddOnsMenu.Submenus.Add(</span><span style="color: #800000;">"</span><span style="color: #800000;">Makovec</span><span style="color: #800000;">"</span><span style="color: #000000;">, </span><span style="color: #800080;">$null</span><span style="color: #000000;">, </span><span style="color: #800080;">$null</span><span style="color: #000000;">)
</span><span style="color: #800080;">$makovecRoot</span><span style="color: #000000;">.Submenus.Add(</span><span style="color: #800000;">'</span><span style="color: #800000;">Run line</span><span style="color: #800000;">'</span><span style="color: #000000;">,{</span><span style="color: #5F9EA0;">RunLine</span><span style="color: #000000;">},</span><span style="color: #800000;">'</span><span style="color: #800000;">CTRL+F8</span><span style="color: #800000;">'</span><span style="color: #000000;">) | </span><span style="color: #5F9EA0; font-weight: bold;">Out-Null</span></pre>
<p>It allows me to be at some line and by pressing Ctrl+F8 just run it:</p>
<p><img class="alignnone" title="Run current line" src="http://www.powershell.cz/images/ISE-run-line/ISE_RunLine.jpg" alt="Run current line" width="678" height="495" /></p>
<p>If you want to see another cool new features in ISE v3, go to <a title="WMF 3.0 CTP2" href="http://www.microsoft.com/download/en/details.aspx?id=27548">Windows Management Framework 3.0 CTP2</a> page and download document named <a href="http://www.microsoft.com/downloads/info.aspx?na=41&amp;srcfamilyid=94895b51-8376-45ec-8fdd-4fd472e49aa3&amp;srcdisplaylang=en&amp;u=http%3a%2f%2fdownload.microsoft.com%2fdownload%2fA%2fF%2f1%2fAF1D6992-54EC-47CD-B2BF-38A68C171641%2fWindows%20PowerShell%20ISE.pdf">Windows PowerShell ISE.pdf</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://powershell.cz/2012/01/01/ise-run-current-line-without-selecting-aka-v3-feature/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ISE: Add new line below/above current</title>
		<link>http://powershell.cz/2011/12/28/ise-add-new-line-below-current/</link>
		<comments>http://powershell.cz/2011/12/28/ise-add-new-line-below-current/#comments</comments>
		<pubDate>Wed, 28 Dec 2011 16:18:43 +0000</pubDate>
		<dc:creator>makovec</dc:creator>
				<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[ISE]]></category>

		<guid isPermaLink="false">http://powershell.cz/?p=217</guid>
		<description><![CDATA[Today I was playing with PowerShell v3 and was frequently working inside ISE (love it&#8217;s Intellisense feature). I was in this situation few times: As you can see, cursor is at position 0. At this time I want to add new line, so it means go to end of current line and press Enter. I <a href="http://powershell.cz/2011/12/28/ise-add-new-line-below-current/" class="more-link">More &#62;</a>]]></description>
			<content:encoded><![CDATA[<p>Today I was playing with PowerShell v3 and was frequently working inside ISE (love it&#8217;s Intellisense feature). I was in this situation few times:</p>
<p><img class="alignnone" title="Cursor at position zero" src="http://www.powershell.cz/images/newline/cursorISE0position.jpg" alt="Cursor at position zero" width="627" height="53" /></p>
<p>As you can see, cursor is at position 0. At this time I want to add new line, so it means go to end of current line and press Enter. I wanted to automate it. Fortunately ISE object model is self-descriptive, so I created this small Add-on:</p>
<pre>$psise.CurrentPowerShellTab.AddOnsMenu.Submenus.Add(
'Insert line below',
    {
    $psise.CurrentFile.Editor.Select(
        $psise.CurrentFile.Editor.CaretLine,
        $psise.CurrentFile.Editor.GetLineLength($psise.CurrentFile.Editor.CaretLine)+1,
        $psise.CurrentFile.Editor.CaretLine,
        $psise.CurrentFile.Editor.GetLineLength($psise.CurrentFile.Editor.CaretLine)+1)
    $psise.CurrentFile.Editor.InsertText("`n")
    }, "CTRL+ENTER")

$psise.CurrentPowerShellTab.AddOnsMenu.Submenus.Add(
'Shift line',
    {
    $psise.CurrentFile.Editor.Select(
        $psise.CurrentFile.Editor.CaretLine, 1,
        $psise.CurrentFile.Editor.CaretLine, 1)
    $psise.CurrentFile.Editor.InsertText("`n")
    $psise.CurrentFile.Editor.Select(
        $psise.CurrentFile.Editor.CaretLine-1, 1,
        $psise.CurrentFile.Editor.CaretLine-1, 1)
    }, "CTRL+SHIFT+ENTER")</pre>
<p>I added two features: add line below and before (shift line). You can call it either from menu:</p>
<p><img class="alignnone" title="Add-on menu" src="http://www.powershell.cz/images/newline/ISEinsertLine.jpg" alt="Add-on menu" width="399" height="99" /></p>
<p>or via keyboard shortcuts.</p>
]]></content:encoded>
			<wfw:commentRss>http://powershell.cz/2011/12/28/ise-add-new-line-below-current/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>if ($PSVersionTable.PSVersion.Major -eq 3) { Start-Fun }</title>
		<link>http://powershell.cz/2011/09/15/whenpsv3/</link>
		<comments>http://powershell.cz/2011/09/15/whenpsv3/#comments</comments>
		<pubDate>Wed, 14 Sep 2011 22:32:00 +0000</pubDate>
		<dc:creator>makovec</dc:creator>
				<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[Build]]></category>
		<category><![CDATA[v3]]></category>
		<category><![CDATA[Win8]]></category>

		<guid isPermaLink="false">http://powershell.cz/?p=197</guid>
		<description><![CDATA[As you all already read during last day, Microsoft showed Windows 8 at it&#8217;s Build conference. There are big changes in OS and I am sure there will be tons of articles about it. But for PowerShell enthusiasts in means something else. PowerShell version 3 is a part of new OS Today, lot of people <a href="http://powershell.cz/2011/09/15/whenpsv3/" class="more-link">More &#62;</a>]]></description>
			<content:encoded><![CDATA[<p>As you all already read during last day, Microsoft showed Windows 8 at it&#8217;s Build conference. There are big changes in OS and I am sure there will be tons of articles about it. But for PowerShell enthusiasts in means something else. PowerShell version 3 is a part of new OS <img src='http://powershell.cz/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Today, lot of people mentioned the most obvious changes/news/thoughts. To name a few:</p>
<ul>
<li>Dmitry Sotnikov &#8211; <a href="http://dmitrysotnikov.wordpress.com/2011/09/14/first-glimpse-at-powershell-v3/">First Glimpse at PowerShell v3</a></li>
<li>Jonathan Medd: <a href="http://www.jonathanmedd.net/2011/09/powershell-v3-a-quick-first-look.html">PowerShell v3 &#8211; A Quick First Look</a> and <a href="http://www.jonathanmedd.net/2011/09/powershell-ise-v3-now-with-intellisense.html">PowerShell ISE v3 &#8211; Now With IntelliSense</a></li>
<li><a href="http://twitter.com/jaykul">@Jaykul</a> &#8211; had some great tweets about short (and clever as usual) hints</li>
</ul>
<p>After first check, I like following points:</p>
<ul>
<li>IntelliSense in ISE &#8211; it works in both -<a href="http://www.powershell.cz/images/whenpsv3/ISEisScriptPane.jpg"> Script Pane</a> and <a href="http://www.powershell.cz/images/whenpsv3/ISEisCommandPane.jpg">Command Pane</a>. Watch <a href="http://www.powershell.cz/images/whenpsv3/ISEisMethProp.jpg">different icons</a> for different types.</li>
<li><a href="http://www.powershell.cz/images/whenpsv3/ISECommands.jpg">Commands Add-on</a> in ISE - for me it looks like great tool for people new to PowerShell. They are able to see all possible parameters at one place and can easily fill/add it to current session. It contains question mark button which opens help for active cmdlet. When you fill all necessary parameters, you can insert result to your session. <em>Unfortunately</em> &#8211; it looks to me that it fully works only for cmdlets from core modules (Microsoft.PowerShell.*) and not for functions.</li>
<li><a href="http://www.powershell.cz/images/whenpsv3/ISEregions.jpg">Support for #region</a>, #endregion in ISE &#8211; collapsible.</li>
<li>ISE also support collapsing of expressions in brackets. As you can see on the <a href="http://www.powershell.cz/images/whenpsv3/ISEregions.jpg">picture</a> it&#8217;s also highlighting matching braces.</li>
<li>New way how modules loading work. You can use tab completion for functions even the module is not loaded. Again one point &#8211; what I tested till now it looks that it not work for script module (but need to test more with Export-ModuleMember).</li>
<li>There is a module CimCmdlets - have to check it as it should be useful for my work.</li>
</ul>
<p>Unfortunately I had to work today, so had not as many time as I wanted for some searching <img src='http://powershell.cz/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  Fortunately &#8211; will have holiday for next three weeks, so there will be enough time for other posts.</p>
]]></content:encoded>
			<wfw:commentRss>http://powershell.cz/2011/09/15/whenpsv3/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ChmToMobi Module</title>
		<link>http://powershell.cz/2011/09/11/chmtomobi-module/</link>
		<comments>http://powershell.cz/2011/09/11/chmtomobi-module/#comments</comments>
		<pubDate>Sun, 11 Sep 2011 14:54:24 +0000</pubDate>
		<dc:creator>makovec</dc:creator>
				<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[Kindle]]></category>
		<category><![CDATA[Module]]></category>

		<guid isPermaLink="false">http://powershell.cz/?p=184</guid>
		<description><![CDATA[It&#8217;s a year now since I bought Kindle for me. I have it still with me and frequently need to check PowerShell documentation. It led me to previous articles (1st and 2nd part) where I described in general, how to convert CHM file to MOBI. As I needed to automate it a bit, I created <a href="http://powershell.cz/2011/09/11/chmtomobi-module/" class="more-link">More &#62;</a>]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s a year now since I bought <a title="Kindle" href="http://www.amazon.com/Kindle-Wireless-Reader-Wifi-Graphite/dp/B002Y27P3M">Kindle</a> for me. I have it still with me and frequently need to check PowerShell documentation. It led me to previous articles (<a href="http://powershell.cz/2011/01/05/powershell-help-on-kindle/">1st</a> and <a href="http://powershell.cz/2011/01/07/how-to-work-with-kindlegen/">2nd</a> part) where I described in general, how to convert CHM file to MOBI. As I needed to automate it a bit, I created simple module for conversion process. Whole process is simple:</p>
<ol>
<li><a href="http://www.powershell.cz/files/chm2mobi.zip">Download</a> ZIP file and unzip in to your module folder.</li>
<li>Import module to your session (<em>Import-Module chm2mobi</em>).</li>
<li>Run <em>Convert-ChmToMobi &lt;your_chm_file&gt;.</em></li>
<li>Copy MOBI to your e-reader and enjoy <img src='http://powershell.cz/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </li>
</ol>
<p>To run it successfully, you need to have <a href="http://www.amazon.com/gp/feature.html?ie=UTF8&amp;docId=1000234621">kindlegen</a> installed on your computer and need to set alias <em>kg</em> to point to EXE file. On my PC I did it this way:</p>
<pre>[11]: Get-Alias kg | ft -auto

CommandType Name Definition
----------- ---- ----------
Alias       kg   Dropbox:\Ruzne\KindleGen\kindlegen.exe</pre>
<p>This is example output when generating file for PowerShell help topics (I recommend to use -Verbose parameter so you&#8217;ll see actual state of processing):</p>
<pre>[16]: Convert-ChmToMobi .\PSHelp.chm

***********************************************
* Amazon.com kindlegen(Windows) V1.1 build 99 *
* A command line e-book compiler              *
* Copyright Amazon.com 2010                   *
***********************************************

opt version: try to minimize (default)
Info(prcgen): Added metadata dc:Title        "Title"
Info(prcgen): Added metadata dc:Date         "2011/09/11"
Info(prcgen): Added metadata dc:Creator      "moravec"
Info(prcgen): Added metadata dc:Subject      "Subject"
Info(prcgen): Added metadata dc:Description  "Description"
Info(prcgen): Parsing files  0000374
Warning(prcgen): &lt;INPUT&gt;, &lt;SELECT&gt; or &lt;TEXTAREA&gt; tag does no

Info(prcgen): Resolving hyperlinks
Info(prcgen): Resolving start reading location
Info(prcgen): Added metadata Start reading   "5098"
Info(prcgen): Computing UNICODE ranges used in the book
Info(prcgen): Found UNICODE range: Basic Latin [20..7E]
Info(prcgen): Found UNICODE range: General Punctuation - Windows 1252 [201C..201E]
Info(prcgen): Found UNICODE range: Latin-1 Supplement [A0..FF]
Info(prcgen): Building MOBI file, record count:   0001986
Info(prcgen): Compiling HTML Parser restart information
Info(prcgen): Final stats - text compressed to (in % of original size):  040.46%
Info(prcgen): The document identifier is: "Title"
Info(prcgen): The file format version is V6
Info(prcgen): Saving MOBI file
Info(prcgen): MOBI File successfully generated!</pre>
<p>There are still some points I need to update or change. For example:</p>
<ul>
<li>Easily add own Subject and Description.</li>
<li>Resolve problems when kindlegen alias not presented.</li>
<li>Add more control over generating files &#8211; generate only some files.</li>
<li>Not show kindlegen output when not requested.</li>
<li>Remove files at the end when requested.</li>
</ul>
<div>You can check <em>Get-Help Convert-ChmToMobi</em> if you need more info. <strong>Note:</strong> Time of file processing it really dependent on your HW. On my PC it tool almost 90 minutes to generate MOBI for Lync server, but on Tom&#8217;s (see below) it was about three minutes.</div>
<div>I&#8217;d like to send big thanks Tom Arbuthnot (<a title="Tom's Twitter" href="http://twitter.com/tomarbuthnot">@tomarbuthnot</a>) for initial testing of this module.</div>
]]></content:encoded>
			<wfw:commentRss>http://powershell.cz/2011/09/11/chmtomobi-module/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>A quick file processing</title>
		<link>http://powershell.cz/2011/08/14/quick-file-processing/</link>
		<comments>http://powershell.cz/2011/08/14/quick-file-processing/#comments</comments>
		<pubDate>Sun, 14 Aug 2011 08:09:28 +0000</pubDate>
		<dc:creator>makovec</dc:creator>
				<category><![CDATA[ConfigMgr]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[MMS]]></category>

		<guid isPermaLink="false">http://powershell.cz/?p=161</guid>
		<description><![CDATA[How to pack&#038;go content of MMS 2011 DVDs.]]></description>
			<content:encoded><![CDATA[<p>I <a href="http://twitter.com/#!/makovec/status/100556298059395072">received</a> DVDs from <a href="http://www.mms-2011.com/">MMS</a> on Monday. What a nice day <img src='http://powershell.cz/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  As I wasn&#8217;t in Vegas, these DVDs are opportunity to see all those interesting presentations at home. My wife was out of town this weekend so I had a plan &#8211; MMS party <img src='http://powershell.cz/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  Wanted to watch everything I marked as interesting. My idea was to create one DVD with presentations I selected and play it on TV (and preferably do not leave my bed).</p>
<p>I moved selected folders to one place, you can see structure of BA02 session folder here (it&#8217;s the same for all sessions):</p>
<p><img class="alignnone" title="Show session folder content" src="http://powershell.cz/images/quick-file-processing/MMS_ShowTree.jpg" alt="" width="420" height="220" /></p>
<p>In directory with session code is places file video.wmv. Eh &#8211; not so good to place every video to root of DVD. So I <span style="text-decoration: line-through;">opened explorer and copied every WMV file to specific location, changed it&#8217;s name to session code and did the same for all sessions I selected</span> used PowerShell to process all files. BTW: If you like <strong>Show-Tree</strong>, it&#8217;s part of <a title="PSCX" href="http://pscx.codeplex.com/" target="_blank">PowerShell Community Extensions</a>.</p>
<p>First I wanted to save session names so I&#8217;ll be able to check session content based on file name (ba02.wmv). One place, where the session name is mentioned, is second line of media.js file:</p>
<p><img class="alignnone" title="media.js file content" src="http://powershell.cz/images/quick-file-processing/MMS_MediaJsContent.jpg" alt="" width="846" height="134" /></p>
<p class="code">PS ToBurn:\&gt; Get-ChildItem -Include media.js -Recurse |% { (Get-Content $_)[1] -match &#8216;^{&#8220;title&#8221;:&#8221;(.*?)&#8221;,&#8217; | Out-Null; $matches[1] }<br />
BA01 &#8211; Configuration Manager State of the Union<br />
BA02 &#8211; Configuration Manager 2007 R3: Technical Update<br />
BA03 &#8211; Configuration Manager 2012 &#8211; Technical Overview<br />
BA04 &#8211; Configuration Manager 2012: Application Management (Part 1 of 3)<br />
BA05 &#8211; Configuration Manager 2012: Application Management (Part 2 of 3)<br />
BA06 &#8211; Configuration Manager 2012: Migrating from 2007 to 2012<br />
&#8230;</p>
<p>As I was working in console (I use aliases as much as possible) and wanted to store this list for future check, my actual command was:</p>
<p class="code">PS ToBurn:\&gt; ls -i media.js -r |% { (gc $_)[1] -match &#8216;^{&#8220;title&#8221;:&#8221;(.*?)&#8221;,&#8217; | Out-Null; $matches[1] } | Out-Printer</p>
<p>Voila &#8211; <strong>Out-Printer</strong> useful again <img src='http://powershell.cz/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Second I needed to move video files to my burn folder and rename it.</p>
<p class="code">PS ToBurn:\&gt; ls -i video.wmv -r |% { Move-Item $_ -Destination $(&#8216;ToBurn:\&#8217;+$(Split-path $_.DirectoryName -Leaf)+&#8217;.wmv&#8217;) }</p>
<p>For all WMV files, I moved them to root of ToBurn PSDrive and renamed based on pattern &lt;folder_name&gt;.wmv.</p>
<p>Last point was to remove everything except video files:</p>
<p class="code">PS ToBurn:\&gt; ls * -r |? {$_.name -notlike &#8216;*.wmv&#8217;} | del -force</p>
<p>OK &#8211; then just burn what I just selected and MMS party can begin.</p>
<p><strong>Conclusion:</strong> When I put DVD to my player, it reported: &#8220;Resolution not supported.&#8221; So I used my common solution: notebook + VGA cable.</p>
]]></content:encoded>
			<wfw:commentRss>http://powershell.cz/2011/08/14/quick-file-processing/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Book: Learn Windows PowerShell in a Month of Lunches</title>
		<link>http://powershell.cz/2011/04/30/book-learn-windows-powershell-in-a-month-of-lunches/</link>
		<comments>http://powershell.cz/2011/04/30/book-learn-windows-powershell-in-a-month-of-lunches/#comments</comments>
		<pubDate>Sat, 30 Apr 2011 20:45:19 +0000</pubDate>
		<dc:creator>makovec</dc:creator>
				<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[book]]></category>
		<category><![CDATA[review]]></category>

		<guid isPermaLink="false">http://powershell.cz/?p=153</guid>
		<description><![CDATA[I like PowerShell books. Every time I hear about a new one, I am impatiently waiting, or &#8211; even better &#8211; I immediately buy it in some version of early access program. That&#8217;s why I like Manning&#8216;s MEAP (Manning Early Access Program). If you don&#8217;t know it &#8211; you&#8217;ll pay a price for electronic version of book <a href="http://powershell.cz/2011/04/30/book-learn-windows-powershell-in-a-month-of-lunches/" class="more-link">More &#62;</a>]]></description>
			<content:encoded><![CDATA[<p><img class="alignleft" title="Book cover" src="http://powershell.cz/images/BookJonesMonth/jones_cover150.jpg" alt="Book cover" width="150" height="188" />I like PowerShell books. Every time I hear about a new one, I am impatiently waiting, or &#8211; even better &#8211; I immediately buy it in some version of early access program. That&#8217;s why I like <a title="manning.com" href="http://manning.com/" target="_self">Manning</a>&#8216;s <a title="MEAP" href="http://manning.com/about/meap" target="_self">MEAP</a> (Manning Early Access Program). If you don&#8217;t know it &#8211; you&#8217;ll pay a price for electronic version of book and as soon new chapter is finished by author, you receive it in PDF. You can read the book during it&#8217;s creation and you can also post your comments (or errors you find) to Author forum so you can influence final version of the book. I like it as it&#8217;s a way how I personally can give something back to PowerShell community.</p>
<p>Last addition to my library is book from <a title="Don Jones" href="http://twitter.com/concentrateddon" target="_self">Don Jones</a> &#8211; <a href="http://manning.com/jones/" target="_self">Learn Windows PowerShell in a Month of Lunches</a>. Don is well known author, speaker and trainer and he&#8217;s also PowerShell MVP. I like what <a title="jsnover" href="http://twitter.com/jsnover" target="_self">Jeffrey Snover</a> wrote about Don: &#8220;If you ever find yourself thinking Don is wrong about something he says about PowerShell, your best bet is to double check first. I invented the thing and that is MY policy. (seriously)&#8221;. You can find whole &#8220;funny&#8221; discussion <a href="http://www.windowsitpro.com/blogs/PowerShellwithaPurpose/tabid/2248/entryid/12923/Default.aspx">here</a>.</p>
<p>Basic idea of the book is easy &#8211; every chapter will take you an hour so you can study it during your lunch. I did it this way during Early Access period and can say it works. I took my notebook to our company&#8217;s cafeteria I spent nice times with learning. What&#8217;s inside the book? You can find whole <a title="TOC" href="http://manning.com/jones/excerpt_contents.html" target="_self">table of contents</a> at Manning web but let me mention the chapter I found most useful for me (Please note &#8211; it&#8217;s my personal opinion, don&#8217;t want to tell that other chapters are not useful!).</p>
<ul>
<li><strong>Chapter 3: Using the help system</strong> &#8211; if there should be just one chapter to read &#8211; it&#8217;s this one. As PowerShell contains really great help system, if you learn how to use it, you are on a good way to be successful. Sometimes I am surprised how people are unwilling to read help.  For me &#8211; help is the key to PowerShell mastery.</li>
<li><strong>Chapter 6: Objects: just data by another name</strong> &#8211; Whole PowerShell is about objects, so you need to understand what the object is, what is method or property.</li>
<li><strong>Chapter 7: The pipeline, deeper</strong> &#8211; another core concept. It&#8217;s first touched in chapter four but in this chapter you&#8217;ll see what&#8217;s ByValue, ByPropertyName or how to use custom properties using <a title="Select-Object" href="http://go.microsoft.com/fwlink/?LinkID=113387" target="_self">Select-Object</a> cmdlet.</li>
<li><strong>Chapter 13: Working with bunches of objects, one at a time</strong> &#8211; this chapter shows you when (and why!) to use &#8220;direct piping&#8221; to cmdlet (Get-Service | Stop-Service), when use <a title="ForEach-Object" href="http://go.microsoft.com/fwlink/?LinkID=113300" target="_self">ForEach-Object</a> (Get-Service | ForEach-Object { $_.Stop() }) and also mentions some other methods. In this chapter you&#8217;ll find how to use pipeline effectively.</li>
<li><strong>Chapter 17: You call this scripting?</strong> &#8211; here you&#8217;ll find how to create scripts with parameters and it&#8217;s own help. This chapter also contains description how pipeline(s) works when calling multiple commands and you&#8217;ll learn a bit about scoping.</li>
<li><strong>Chapter 21: Creating your own “cmdlets” and modules</strong> &#8211; shows you how to make your functions &#8220;pipeline ready&#8221; and how to reuse them using modules.</li>
<li><strong>Chapters 24 &amp; 28</strong> &#8211; those are a bit special and contains some useful tips/tricks/gotchas you&#8217;ll find during your learning process.</li>
</ul>
<p>Every main chapter of the book contains also Lab section, so you can practice what you learned. Most chapters contains also <em>Common points of confusion</em> part &#8211; here Don mentions commons mistakes he frequently see when teaching PowerShell &#8211; so you can avoid it in your life.</p>
<p>There is also support web page you can use. It&#8217;s accessible at <a title="morelunches.com" href="http://morelunches.com/titles/windows-powershell-v2/" target="_self">morelunches.com</a> and contains all lab answers. Best part of the web are video demos for every chapter &#8211; I found it pretty useful. You can find more videos at Don&#8217;s <a title="YouTube Channel" href="http://www.youtube.com/user/ConcentratedDon" target="_self">YouTube Channel</a>.</p>
<p>Even this book is intended for administrators who are starting with PowerShell, I can say that also intermediate users can learn something useful. Starting today, if someone ask me what to recommend for PowerShell newbie, this book is my answer.</p>
]]></content:encoded>
			<wfw:commentRss>http://powershell.cz/2011/04/30/book-learn-windows-powershell-in-a-month-of-lunches/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Command running time</title>
		<link>http://powershell.cz/2011/04/02/command-running-time/</link>
		<comments>http://powershell.cz/2011/04/02/command-running-time/#comments</comments>
		<pubDate>Sat, 02 Apr 2011 20:43:03 +0000</pubDate>
		<dc:creator>makovec</dc:creator>
				<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[history]]></category>
		<category><![CDATA[prompt]]></category>

		<guid isPermaLink="false">http://powershell.cz/?p=118</guid>
		<description><![CDATA[This week, James Brundage posted article named Two Ways to Time PowerShell Commands. There was mentioned very neat trick to check running time of last command. Please read that article first to understand what I am talking about. I created a function to have easier way to call that command. It&#8217;s not so hard, so <a href="http://powershell.cz/2011/04/02/command-running-time/" class="more-link">More &#62;</a>]]></description>
			<content:encoded><![CDATA[<p>This week, <a href="http://start-automating.com/AboutUs.html" target="_self">James Brundage</a> posted article named <a href="http://blog.start-automating.com/post/2011/03/30/Two-Ways-to-Time-PowerShell-Commands.aspx" target="_self">Two Ways to Time PowerShell Commands</a>. There was mentioned very neat trick to check running time of last command. Please read that article first to understand what I am talking about.</p>
<p>I created a function to have easier way to call that command. It&#8217;s not so hard, so here is it:</p>
<pre><span style="color: #0000ff;">function</span><span style="color: #000000;"> </span><span style="color: #5f9ea0;">Get-HistoryItemRunningTime</span><span style="color: #000000;">
{
</span><span style="color: #008000;">&lt;#</span><span style="color: #008000;">
.SYNOPSIS
Displays running for given item from history

.DESCRIPTION
For given history ID (or last command) displays running time.

.PARAMETER Id
Specifies history ID to be used.

.INPUTS
None. You cannot pipe objects to Get-HistoryItemRunningTime.

.OUTPUTS
System.TimeSpan.

.EXAMPLE
C:\PS&gt; Get-HistoryItemRunningTime 3

Days              : 0
Hours             : 0
Minutes           : 0
Seconds           : 0
Milliseconds      : 578
Ticks             : 5781250
TotalDays         : 6.69126157407407E-06
TotalHours        : 0.000160590277777778
TotalMinutes      : 0.00963541666666667
TotalSeconds      : 0.578125
TotalMilliseconds : 578.125

Displays running time for command ID #3.

.EXAMPLE
PS C:\&gt; Start-Sleep 2
PS C:\&gt; Get-HistoryItemRunningTime

Days              : 0
Hours             : 0
Minutes           : 0
Seconds           : 2
Milliseconds      : 15
Ticks             : 20156250
TotalDays         : 2.33289930555556E-05
TotalHours        : 0.000559895833333333
TotalMinutes      : 0.03359375
TotalSeconds      : 2.015625
TotalMilliseconds : 2015.625

Displays running time for last command.

.LINK
Get-History
</span><span style="color: #008000;">#&gt;</span><span style="color: #000000;">     

    </span><span style="color: #0000ff;">param</span><span style="color: #000000;"> (
        [</span><span style="color: #008080;">int64</span><span style="color: #000000;">]</span><span style="color: #800080;">$Id</span><span style="color: #000000;">
    )

    </span><span style="color: #0000ff;">if</span><span style="color: #000000;"> (</span><span style="color: #800080;">$Id</span><span style="color: #000000;">)
    {
        </span><span style="color: #800080;">$history</span><span style="color: #000000;"> </span><span style="color: #ff0000;">=</span><span style="color: #000000;"> </span><span style="color: #5f9ea0; font-weight: bold;">Get-History</span><span style="color: #000000;"> </span><span style="color: #5f9ea0; font-style: italic;">-Id</span><span style="color: #000000;"> </span><span style="color: #800080;">$Id</span><span style="color: #000000;">
    }
    </span><span style="color: #0000ff;">else</span><span style="color: #000000;">
    {
        </span><span style="color: #800080;">$history</span><span style="color: #000000;"> </span><span style="color: #ff0000;">=</span><span style="color: #000000;"> </span><span style="color: #5f9ea0; font-weight: bold;">Get-History</span><span style="color: #000000;"> </span><span style="color: #5f9ea0; font-style: italic;">-Count</span><span style="color: #000000;"> </span><span style="color: #000000;">1</span><span style="color: #000000;">
    }

    </span><span style="color: #0000ff;">return</span><span style="color: #000000;"> (</span><span style="color: #800080;">$history</span><span style="color: #000000;">.EndExecutionTime </span><span style="color: #ff0000;">-</span><span style="color: #000000;"> </span><span style="color: #800080;">$history</span><span style="color: #000000;">.StartExecutionTime)

}</span></pre>
<p>I then decided to make it a bit more useful. What to put it to profile? Hmm. So I modified also my prompt function.</p>
<p><strong>Note:</strong> I have fully customized prompt in my profile. In following example I just show the idea, not my current prompt.</p>
<pre><span style="color: #800080;">$OrigTitle</span><span style="color: #000000;"> </span><span style="color: #ff0000;">=</span><span style="color: #000000;"> </span><span style="color: #800080;">$host</span><span style="color: #000000;">.</span><span style="color: #8b4513;">UI</span><span style="color: #000000;">.</span><span style="color: #8b4513;">RawUI</span><span style="color: #000000;">.</span><span style="color: #8b4513;">WindowTitle</span><span style="color: #000000;">
</span><span style="color: #800080;">$ShowRunningTime</span><span style="color: #000000;"> </span><span style="color: #ff0000;">=</span><span style="color: #000000;"> </span><span style="color: #800080;">$false</span><span style="color: #000000;">

</span><span style="color: #0000ff;">function</span><span style="color: #000000;"> </span><span style="color: #5f9ea0;">prompt</span><span style="color: #000000;">
{
  </span><span style="color: #0000ff;">if</span><span style="color: #000000;">(</span><span style="color: #800080;">$ShowRunningTime</span><span style="color: #000000;">)
   {
      </span><span style="color: #800080;">$host</span><span style="color: #000000;">.</span><span style="color: #8b4513;">UI</span><span style="color: #000000;">.</span><span style="color: #8b4513;">RawUI</span><span style="color: #000000;">.</span><span style="color: #8b4513;">WindowTitle</span><span style="color: #000000;"> </span><span style="color: #ff0000;">=</span><span style="color: #000000;"> </span><span style="color: #800000;">"</span><span style="color: #800000;">$OrigTitle Time: $(Get-HistoryItemRunningTime)</span><span style="color: #800000;">"</span><span style="color: #000000;">
   }
   </span><span style="color: #0000ff;">else</span><span style="color: #000000;">
   {
    </span><span style="color: #800080;">$host</span><span style="color: #000000;">.</span><span style="color: #8b4513;">UI</span><span style="color: #000000;">.</span><span style="color: #8b4513;">RawUI</span><span style="color: #000000;">.</span><span style="color: #8b4513;">WindowTitle</span><span style="color: #000000;"> </span><span style="color: #ff0000;">=</span><span style="color: #000000;"> </span><span style="color: #800080;">$OrigTitle</span><span style="color: #000000;">
   }
}</span></pre>
<p>So now I can run it this way</p>
<p><img class="alignnone" title="Get-HistoryItemRunningTime" src="http://powershell.cz/images/Commandrunningtime/ghit.jpg" alt="Get-HistoryItemRunningTime" width="416" height="69" /></p>
<p>and if you don&#8217;t want to see the time in title, you can just run it for specific history item (please note that <em>ghit</em> is an alias for <em>Get-HistoryItemRunningTime</em>).</p>
<p class="code">PS&gt; h<br />
Id CommandLine<br />
&#8211; &#8212;&#8212;&#8212;&#8211;<br />
1 ghit<br />
2 Start-Sleep 2<br />
3 gps | Out-Null<br />
4 get-date<br />
PS&gt; ghit 2<br />
&nbsp;<br />
Days              : 0<br />
Hours             : 0<br />
Minutes           : 0<br />
Seconds           : 2<br />
Milliseconds      : 15<br />
Ticks             : 20156250<br />
TotalDays         : 2.33289930555556E-05<br />
TotalHours        : 0.000559895833333333<br />
TotalMinutes      : 0.03359375<br />
TotalSeconds      : 2.015625<br />
TotalMilliseconds : 2015.625<br />
&nbsp;<br />
PS&gt; ghit<br />
&nbsp;<br />
Days              : 0<br />
Hours             : 0<br />
Minutes           : 0<br />
Seconds           : 0<br />
Milliseconds      : 62<br />
Ticks             : 625000<br />
TotalDays         : 7.2337962962963E-07<br />
TotalHours        : 1.73611111111111E-05<br />
TotalMinutes      : 0.00104166666666667<br />
TotalSeconds      : 0.0625<br />
TotalMilliseconds : 62.5</p>
<p>Thank you, James, for nice trick <img src='http://powershell.cz/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://powershell.cz/2011/04/02/command-running-time/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Virus Definition File version in registry</title>
		<link>http://powershell.cz/2011/03/30/virus-definition-file-version-in-registry/</link>
		<comments>http://powershell.cz/2011/03/30/virus-definition-file-version-in-registry/#comments</comments>
		<pubDate>Wed, 30 Mar 2011 20:11:14 +0000</pubDate>
		<dc:creator>makovec</dc:creator>
				<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[-f]]></category>
		<category><![CDATA[regex]]></category>
		<category><![CDATA[SAV]]></category>

		<guid isPermaLink="false">http://powershell.cz/?p=91</guid>
		<description><![CDATA[Today I have a quick post. My friend called me that he needs to check SAV definition date which is stored in registry. It is also available in Symantec AntiVirus GUI But &#8211; unfortunately &#8211; the value in registry is hex number which needs to be converted to readable format. Whole idea is described at <a href="http://powershell.cz/2011/03/30/virus-definition-file-version-in-registry/" class="more-link">More &#62;</a>]]></description>
			<content:encoded><![CDATA[<p>Today I have a quick post. My friend called me that he needs to check SAV definition date which is stored in registry. It is also available in Symantec AntiVirus GUI</p>
<p><img class="alignnone" title="SAVdef" src="http://www.powershell.cz/images/virus-definition-file-version-in-registry/SAVdef.jpg" alt="SAVdef" width="195" height="35" /></p>
<p>But &#8211; unfortunately &#8211; the value in registry is hex number which needs to be converted to readable format. Whole idea is described at <a href="http://www.symantec.com/docs/TECH131952" target="_self">Symantec&#8217;s web</a>. As he was interested in PowerShell solution (another one converted) I quickly created short function:</p>
<pre><span style="color: #0000ff;">function</span><span style="color: #000000;"> </span><span style="color: #5f9ea0;">Get-SAVdefs</span><span style="color: #000000;">
{
    </span><span style="color: #0000ff;">param</span><span style="color: #000000;"> (</span><span style="color: #800080;">$def</span><span style="color: #000000;"> </span><span style="color: #ff0000;">=</span><span style="color: #000000;"> (</span><span style="color: #000000;"><span style="color: #5f9ea0;"><strong>Get-ItemProperty</strong></span></span><span style="color: #000000;"> HKLM:\</span><span style="color: #800000;">SOFTWARE\INTEL\LANDesk\VirusProtect6\CurrentVersion</span><span style="color: #000000;">).UsingPattern )

    [</span><span style="color: #008080;">Convert</span><span style="color: #000000;">]::</span><span style="color: #8b4513;">ToString</span><span style="color: #000000;">(</span><span style="color: #800080;">$def</span><span style="color: #000000;">, </span><span style="color: #000000;">2</span><span style="color: #000000;">) </span><span style="color: #ff0000;">-match</span><span style="color: #000000;"> </span><span style="color: #800000;">"</span><span style="color: #800000;">^(?&lt;year&gt;\d*)(?&lt;month&gt;\d{4})(?&lt;day&gt;\d{5})(?&lt;rev&gt;\d{9})$</span><span style="color: #800000;">"</span><span style="color: #000000;"> | </span><span style="color: #5f9ea0; font-weight: bold;">Out-Null</span><span style="color: #000000;">

    </span><span style="color: #800000;">"</span><span style="color: #800000;">{0}/{1}/{2} Rev {3}</span><span style="color: #800000;">"</span><span style="color: #000000;"> </span><span style="color: #ff0000;">-f</span><span style="color: #000000;"> $([</span><span style="color: #008080;">Convert</span><span style="color: #000000;">]::</span><span style="color: #8b4513;">ToInt32</span><span style="color: #000000;">(</span><span style="color: #800080;">$matches</span><span style="color: #000000;">.year, </span><span style="color: #000000;">2</span><span style="color: #000000;">) </span><span style="color: #ff0000;">+</span><span style="color: #000000;"> </span><span style="color: #000000;">1998</span><span style="color: #000000;">),
        [</span><span style="color: #008080;">Convert</span><span style="color: #000000;">]::</span><span style="color: #8b4513;">ToInt32</span><span style="color: #000000;">(</span><span style="color: #800080;">$matches</span><span style="color: #000000;">.month, </span><span style="color: #000000;">2</span><span style="color: #000000;">),
        [</span><span style="color: #008080;">Convert</span><span style="color: #000000;">]::</span><span style="color: #8b4513;">ToInt32</span><span style="color: #000000;">(</span><span style="color: #800080;">$matches</span><span style="color: #000000;">.day, </span><span style="color: #000000;">2</span><span style="color: #000000;">),
        [</span><span style="color: #008080;">Convert</span><span style="color: #000000;">]::</span><span style="color: #8b4513;">ToInt32</span><span style="color: #000000;">(</span><span style="color: #800080;">$matches</span><span style="color: #000000;">.rev, </span><span style="color: #000000;">2</span><span style="color: #000000;">)
}</span></pre>
<p>So it can be used this way:</p>
<p class="code">PS C:\Scripts &gt; Get-SAVdefs<br />
2011/3/29 Rev 5<br />
PS C:\Scripts &gt; Get-SAVdefs 0x312e02<br />
2010/4/23 Rev 2</p>
<p>As a parameter is used direct path to the registry he provided. Then, the value found is processed with <a href="http://technet.microsoft.com/en-us/library/dd315294.aspx" target="_self">regex</a>. It splits binary number based on info found at mentioned web page. Then all values from <em>$matches</em> are written using format operator.</p>
<p>Main work is done with <a href="http://msdn.microsoft.com/en-us/library/system.convert.aspx" target="_self">System.Convert</a> class. It contains few methods for converting numbers, for example to convert number 3652 to binary and back, you can use:</p>
<p class="code">PS C:\Scripts &gt; [convert]::ToString(3652, 2)<br />
111001000100<br/><br/><br />
PS C:\Scripts &gt; [convert]::ToInt16(111001000100, 2)<br />
3652</p>
<p>I am sure you will find some other examples how to use it. BTW: Why 3652? Wait till Friday and you&#8217;ll see <img src='http://powershell.cz/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://powershell.cz/2011/03/30/virus-definition-file-version-in-registry/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

