<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Keith Hill&#039;s Blog</title>
	<atom:link href="http://rkeithhill.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://rkeithhill.wordpress.com</link>
	<description>Just another WordPress.com site</description>
	<lastBuildDate>Thu, 09 May 2013 19:55:39 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='rkeithhill.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Keith Hill&#039;s Blog</title>
		<link>http://rkeithhill.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://rkeithhill.wordpress.com/osd.xml" title="Keith Hill&#039;s Blog" />
	<atom:link rel='hub' href='http://rkeithhill.wordpress.com/?pushpress=hub'/>
		<item>
		<title>Using PowerShell to Analyze Your PC&#8217;s Sleep &amp; Wake Behavior</title>
		<link>http://rkeithhill.wordpress.com/2013/05/08/using-powershell-to-analyze-your-pcs-sleep-wake-behavior/</link>
		<comments>http://rkeithhill.wordpress.com/2013/05/08/using-powershell-to-analyze-your-pcs-sleep-wake-behavior/#comments</comments>
		<pubDate>Thu, 09 May 2013 02:06:10 +0000</pubDate>
		<dc:creator>rkeithhill</dc:creator>
				<category><![CDATA[PowerShell]]></category>

		<guid isPermaLink="false">https://rkeithhill.wordpress.com/?p=278</guid>
		<description><![CDATA[I have some older hardware running Windows 7 Media Center.&#160; Normally we let the Media Center just go to sleep on its own but I’ve been concerned that it isn’t sleeping as much during there wee hours of the morning &#8230; <a href="http://rkeithhill.wordpress.com/2013/05/08/using-powershell-to-analyze-your-pcs-sleep-wake-behavior/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=rkeithhill.wordpress.com&#038;blog=18780344&#038;post=278&#038;subd=rkeithhill&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>I have some older hardware running Windows 7 Media Center.&nbsp; Normally we let the Media Center just go to sleep on its own but I’ve been concerned that it isn’t sleeping as much during there wee hours of the morning as I think it should be.&nbsp; I’ve got Ceton quad tuner card in it that I like to give a chance to cool down.&nbsp; The one problem with our slim form factor Media Center PC is that the cooling isn’t the best. </p>
<p>In order to determine how much the PC sleeps I wrote a small PowerShell script to analyze event log entries.&nbsp; Here are the contents of the script Get-SleepInfo.ps1:</p>
<pre style="overflow:visible;font-size:10pt;font-family:consolas, courier, monospace;color:white;direction:ltr;text-align:left;margin:0;line-height:14pt;width:100%;background-color:#000080;border-style:none;padding:5px;">param($Newest = 50)

function Parse-EventLogEntry
{
    param(
        [Parameter(Mandatory=$true, Position=0, ValueFromPipeline=$true)]
        [System.Diagnostics.EventLogEntry[]]
        $eventInfo
    )

    Process
    {
        foreach ($info in $eventInfo)
        {
            $enterSleep = [DateTime]::Parse($info.ReplacementStrings[0]);
            $exitSleep = [DateTime]::Parse($info.ReplacementStrings[1]);
            $duration = $exitSleep - $enterSleep
            $wakeSource = 'Unknown'
            if ($info.Message -match 'Wake Source:\s*(.*)$')
            {
                $wakeSource = $matches[1]
            }
            new-object psobject -Property @{Duration = $duration; Sleep = $enterSleep; 
                                            Wake = $exitSleep; WakeSource = $wakeSource}
        }
    }
}

Get-EventLog -LogName System -Source Microsoft-Windows-Power-Troubleshooter -Newest $Newest | 
     Sort TimeGenerated | Parse-EventLogEntry
</pre>
<p>&nbsp;</p>
<p>After running this on my MediaCenter PC, I get the following data:</p>
<pre style="overflow:visible;font-size:10pt;font-family:consolas, courier, monospace;color:white;direction:ltr;text-align:left;margin:0;line-height:14pt;width:100%;background-color:#000080;border-style:none;padding:5px;">Duration         Sleep                Wake                 WakeSource
--------         -----                ----                 ----------
01:04:22.2225162 5/2/2013 2:47:08 PM  5/2/2013 3:51:31 PM  5Windows will exec...
00:44:42.9902954 5/3/2013 12:33:23 AM 5/3/2013 1:18:06 AM  5Windows will exec...
00:12:56.0674401 5/3/2013 2:18:08 AM  5/3/2013 2:31:05 AM  5Windows will exec...
06:59:43.2874463 5/3/2013 3:31:08 AM  5/3/2013 10:30:52 AM 0
05:54:48.3185846 5/4/2013 5:01:08 AM  5/4/2013 10:55:57 AM 0
00:30:09.8591193 5/5/2013 1:15:01 AM  5/5/2013 1:45:11 AM  5Windows will exec...
05:30:49.2332622 5/5/2013 5:01:04 AM  5/5/2013 10:31:54 AM 0
03:12:13.2579267 5/6/2013 5:02:20 AM  5/6/2013 8:14:33 AM  0
00:14:30.6312742 5/7/2013 1:25:14 AM  5/7/2013 1:39:45 AM  5Windows will exec...
00:11:23.6864251 5/7/2013 2:39:59 AM  5/7/2013 2:51:23 AM  5Windows will exec...
04:18:45.8838138 5/7/2013 4:34:44 AM  5/7/2013 8:53:30 AM  0
01:19:03.7671589 5/7/2013 12:46:44 PM 5/7/2013 2:05:48 PM  0
00:37:13.6740184 5/8/2013 12:59:29 AM 5/8/2013 1:36:43 AM  5Windows will exec...
00:01:11.1209186 5/8/2013 2:36:57 AM  5/8/2013 2:38:09 AM  5Windows will exec...
02:13:18.0939494 5/8/2013 3:38:12 AM  5/8/2013 5:51:31 AM  5Windows will exec...
</pre>
<p>&nbsp;</p>
<p>The problematic wake source above (truncated in this output to fit the blog post width) is:</p>
<p><font size="2" face="Consolas">5Windows will execute &#8216;\Microsoft\Windows\Media Center\mcupdate_scheduled&#8217; scheduled task that requested waking the computer.</font></p>
<p>Ah, good ol’ mcupdate_scheduled is configured to wake the computer if it is asleep.&nbsp; This situation is quickly fixed with a little tweak to the scheduled task to a) not wake the computer and b) change the trigger to a time the computer is likely to be on.&nbsp; With this tweak hopefully the MediaCenter will now sleep through the night.</p>
<p><strong>Update</strong>: after tweaking the scheduled task “mcupdate_scheduled”, my Media Center PC slept for a good 12 hours before *I* woke it up:</p>
<pre style="overflow:visible;font-size:10pt;font-family:consolas, courier, monospace;color:white;direction:ltr;text-align:left;margin:0;line-height:14pt;width:100%;background-color:#000080;border-style:none;padding:5px;">02:13:18.0939494 5/8/2013 3:38:12 AM  5/8/2013 5:51:31 AM  5Windows will exec...
12:15:24.3601661 5/9/2013 1:24:42 AM  5/9/2013 1:40:07 PM  0</pre>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/rkeithhill.wordpress.com/278/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/rkeithhill.wordpress.com/278/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=rkeithhill.wordpress.com&#038;blog=18780344&#038;post=278&#038;subd=rkeithhill&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://rkeithhill.wordpress.com/2013/05/08/using-powershell-to-analyze-your-pcs-sleep-wake-behavior/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://2.gravatar.com/avatar/bcc517cd604f90500c5dcef5a6ed7f81?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">rkeithhill</media:title>
		</media:content>
	</item>
		<item>
		<title>PowerShell Script that Relaunches as Admin</title>
		<link>http://rkeithhill.wordpress.com/2013/04/05/powershell-script-that-relaunches-as-admin/</link>
		<comments>http://rkeithhill.wordpress.com/2013/04/05/powershell-script-that-relaunches-as-admin/#comments</comments>
		<pubDate>Fri, 05 Apr 2013 15:08:17 +0000</pubDate>
		<dc:creator>rkeithhill</dc:creator>
				<category><![CDATA[PowerShell]]></category>

		<guid isPermaLink="false">https://rkeithhill.wordpress.com/?p=276</guid>
		<description><![CDATA[If were following good security practices we run our Windows system with UAC enabled.&#160; This means that if you forget to launch your PowerShell prompt as Administrator when you run a script that requires administrative privilege then that script will &#8230; <a href="http://rkeithhill.wordpress.com/2013/04/05/powershell-script-that-relaunches-as-admin/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=rkeithhill.wordpress.com&#038;blog=18780344&#038;post=276&#038;subd=rkeithhill&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>If were following good security practices we run our Windows system with UAC enabled.&nbsp; This means that if you forget to launch your PowerShell prompt as Administrator when you run a script that requires administrative privilege then that script will fail. </p>
<p>It would be nice to build a mechanism into our script to “auto-elevate” if UAC is enabled.&nbsp; The trick to doing this is to run Start-Process –verb runas.&nbsp; After that you only need to figure out if the current user is an administrator and if UAC is enabled.&nbsp; And you have to package up the script’s parameters as an array of strings.&nbsp; All of this can be accomplished fairly easily with this bit of PowerShell script:</p>
<div id="codeSnippetWrapper">
<pre id="codeSnippet" style="overflow:visible;font-size:8pt;font-family:'Courier New', courier, monospace;color:black;direction:ltr;text-align:left;margin:0;line-height:12pt;width:100%;background-color:#f4f4f4;border-style:none;padding:0;"><p><span style="color:#0000ff;">function</span> IsAdministrator<br />{<br />    $Identity = [System.Security.Principal.WindowsIdentity]::GetCurrent()<br />    $Principal = New-Object System.Security.Principal.WindowsPrincipal($Identity)<br />    $Principal.IsInRole([System.Security.Principal.WindowsBuiltInRole]::Administrator)<br />}<br /><br /><br /><span style="color:#0000ff;">function</span> IsUacEnabled<br />{<br />    (Get-ItemProperty HKLM:\Software\Microsoft\Windows\CurrentVersion\Policies\System).EnableLua <span style="color:#cc6633;">-ne</span> 0<br />}<br /><br /><span style="color:#008000;">#</span><br /><span style="color:#008000;"># Main script</span><br /><span style="color:#008000;">#</span><br /><span style="color:#0000ff;">if</span> (!(IsAdministrator))<br />{<br />    <span style="color:#0000ff;">if</span> (IsUacEnabled)<br />    {<br />        [string[]]$argList = @(<span style="color:#006080;">'-NoProfile'</span>, <span style="color:#006080;">'-NoExit'</span>, <span style="color:#006080;">'-File'</span>, $MyInvocation.MyCommand.Path)<br />        $argList += $MyInvocation.BoundParameters.GetEnumerator() | Foreach {<span style="color:#006080;">"-$($_.Key)"</span>, <span style="color:#006080;">"$($_.Value)"</span>}<br />        $argList += $MyInvocation.UnboundArguments<br />        Start-Process PowerShell.exe -Verb Runas -WorkingDirectory $pwd -ArgumentList $argList <br />        <span style="color:#0000ff;">return</span><br />    }<br />    <span style="color:#0000ff;">else</span><br />    {<br />        <span style="color:#0000ff;">throw</span> <span style="color:#006080;">"You must be administrator to run this script"</span><br />    }<br />}</p></pre>
<p></div>
<p>If you launch this script from a non-elevated context, it will fire up a new PoweShell session that is elevated assuming UAC is enabled. </p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/rkeithhill.wordpress.com/276/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/rkeithhill.wordpress.com/276/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=rkeithhill.wordpress.com&#038;blog=18780344&#038;post=276&#038;subd=rkeithhill&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://rkeithhill.wordpress.com/2013/04/05/powershell-script-that-relaunches-as-admin/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
	
		<media:content url="http://2.gravatar.com/avatar/bcc517cd604f90500c5dcef5a6ed7f81?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">rkeithhill</media:title>
		</media:content>
	</item>
		<item>
		<title>Windows PowerShell V3 Language Specification Posted</title>
		<link>http://rkeithhill.wordpress.com/2013/01/11/windows-powershell-v3-language-specification-posted/</link>
		<comments>http://rkeithhill.wordpress.com/2013/01/11/windows-powershell-v3-language-specification-posted/#comments</comments>
		<pubDate>Fri, 11 Jan 2013 15:52:14 +0000</pubDate>
		<dc:creator>rkeithhill</dc:creator>
				<category><![CDATA[PowerShell 3.0]]></category>

		<guid isPermaLink="false">https://rkeithhill.wordpress.com/?p=275</guid>
		<description><![CDATA[You can download it here.<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=rkeithhill.wordpress.com&#038;blog=18780344&#038;post=275&#038;subd=rkeithhill&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>You can download it <a href="http://www.microsoft.com/en-us/download/details.aspx?id=36389">here</a>.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/rkeithhill.wordpress.com/275/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/rkeithhill.wordpress.com/275/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=rkeithhill.wordpress.com&#038;blog=18780344&#038;post=275&#038;subd=rkeithhill&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://rkeithhill.wordpress.com/2013/01/11/windows-powershell-v3-language-specification-posted/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://2.gravatar.com/avatar/bcc517cd604f90500c5dcef5a6ed7f81?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">rkeithhill</media:title>
		</media:content>
	</item>
		<item>
		<title>PSCX 2.1 and 3.0 Release Candidates Posted</title>
		<link>http://rkeithhill.wordpress.com/2012/09/15/pscx-2-1-and-3-0-release-candidates-posted/</link>
		<comments>http://rkeithhill.wordpress.com/2012/09/15/pscx-2-1-and-3-0-release-candidates-posted/#comments</comments>
		<pubDate>Sun, 16 Sep 2012 02:45:47 +0000</pubDate>
		<dc:creator>rkeithhill</dc:creator>
				<category><![CDATA[PowerShell 2.0]]></category>
		<category><![CDATA[PowerShell 3.0]]></category>
		<category><![CDATA[PSCX]]></category>

		<guid isPermaLink="false">https://rkeithhill.wordpress.com/?p=271</guid>
		<description><![CDATA[Oisin and I have been busy prepping the PowerShell Community Extensions to support Windows PowerShell 3.0.&#160; With this release, we are providing two packages.&#160; There is a Pscx-2.1.0-RC.zip that is xcopy deployable just like PSCX 2.0.&#160; Just remember to unblock &#8230; <a href="http://rkeithhill.wordpress.com/2012/09/15/pscx-2-1-and-3-0-release-candidates-posted/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=rkeithhill.wordpress.com&#038;blog=18780344&#038;post=271&#038;subd=rkeithhill&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>Oisin and I have been busy prepping the PowerShell Community Extensions to support Windows PowerShell 3.0.&nbsp; With this release, we are providing two packages.&nbsp; There is a <a href="http://pscx.codeplex.com/releases/view/93945" target="_blank">Pscx-2.1.0-RC.zip</a> that is xcopy deployable just like PSCX 2.0.&nbsp; Just remember to unblock the ZIP before extracting it otherwise you’ll get errors when you try to import the module.&nbsp; Pscx 2.1 can be used to target both Windows PowerShell 2.0 and 3.0.&nbsp; In order to do this, Pscx 2.1 is still compiled against .NET 2.0 and it can’t take advantage of any Windows PowerShell 3.0 specific features.&nbsp; </p>
<p>The second package is <a href="http://pscx.codeplex.com/releases/view/94637" target="_blank">Pscx-3.0.0-RC.msi</a>.&nbsp; This is a traditional Windows installer package.&nbsp; The benefit of using an MSI is that the user doesn’t have to worry about unblocking the file before installing it.&nbsp; The MSI file is also Authenticode signed with an extended validation code signing certificate so it should make it past Windows 8 SmartScreen.&nbsp; I’d like to extend a big thanks to <a href="http://www.digicert.com/">DigiCert</a> for graciously donating the EV code signing certificate to us.</p>
<p>INSTALLATION NOTE: the WiX-based installer modifies the PSModulePath environment variable but the modification doesn’t always seem to be in effect after installation.&nbsp; If Import-Module Pscx –RequiredVersion 3.0.0.0 fails to load PSCX, import the module by path (C:\Program Files (x86)\PowerShell Community Extensions\Pscx3\Pscx\Pscx.psd1) until you get a chance to reboot.&nbsp; After that, you shouldn’t have to specify the path.</p>
<p>Another aspect of Pscx 3.0 is that it is compiled against .NET 4.0 and takes advantage of some features specific to Windows PowerShell 3.0.&nbsp; Over time, we will focus our new feature efforts on the Pscx 3.0 branch.</p>
<h3>PSCX 2.1 and 3.0 Side-by-Side Support</h3>
<p>With this release, you can install Pscx 2.1 and 3.0 side-by-side.&nbsp; Note however that if you xcopy install Pscx 2.1 into your user’s Modules directory, PowerShell will find that version of Pscx before the 3.0 version.&nbsp; In order to ensure you load a specific version of Pscx, use the –RequiredVersion parameter on Import-Module e.g.</p>
<pre style="overflow:visible;font-size:10pt;font-family:consolas, courier, monospace;color:white;direction:ltr;text-align:left;margin:0;line-height:14pt;width:100%;background-color:#000080;border-style:none;padding:5px;">Import-Module Pscx -RequiredVersion 3.0.0.0</pre>
<p></p>
<h3>Support for AllSigned Execution Policy</h3>
<p>Each of the two packages above (2.1 and 3.0) supported execution in an AllSigned environment.&nbsp; All of the script files (*.ps1, *.psm1 and *.ps1xml) have been signed.&nbsp; Of course, this means you can’t modify these scripts (i.e. to fix bugs) and still run them AllSigned.</p>
<h3>New Features</h3>
<p>There are not a lot of new features in this release but there are a few handy additions including:</p>
<ul>
<li>Get-Parameter – thanks to Jason Archer for contributing this great way to visual a command’s parameter information.</li>
<li>Import-VisualStudioVars – for developers who like to spend their time in PowerShell instead of cmd.exe, this function takes care of importing the build environment for the specified version of Visual Studio.&nbsp; The 2008, 2010 and 2012 versions of Visual Studio are supported.</li>
<li>Start-PowerShell – a wrapper for PowerShell.exe that utilizes the PowerShell parameter parsing engine to make invocation of various flavors of PowerShell (from PowerShell obviously) easier.&nbsp; While testing the AllSigned support I used this command a lot:
<pre style="overflow:visible;font-size:10pt;font-family:consolas, courier, monospace;color:white;direction:ltr;text-align:left;margin:0;line-height:14pt;width:100%;background-color:#000080;border-style:none;padding:5px;">Start-PowerShell -NoProfile -ExecutionPolicy AllSigned -Version 2</pre>
</li>
<li>Get-ExecutionTime – since PowerShell 2.0, the HistoryInfo object for a command has included both the StartExecutionTime and the EndExecutionTime. This command makes it easy to see the total execution time for any command e.g.:
</li>
</ul>
<p>
<pre style="overflow:visible;font-size:10pt;font-family:consolas, courier, monospace;color:white;direction:ltr;text-align:left;margin:0;line-height:14pt;width:100%;background-color:#000080;border-style:none;padding:5px;">C:\PS&gt; Get-ExecutionTime

  Id ExecutionTime    HistoryInfo
  -- -------------    -----------
   1 00:00:02.9919258 Get-ChildItem C:\Windows\System32
   2 00:00:00.2650339 Get-Process
   3 00:00:00.2499424 Get-Service</pre>
</p>
<h3>Bug Fixes</h3>
<p>Oisin spent a good deal of time fixing issues in the Read-Archive and Expand-Archive cmdlets.&nbsp; We updated the version of 7z that we are using (to 9.x) and modified the cmdlets to use <a href="http://sevenzipsharp.codeplex.com/">SevenZipSharp</a>.&nbsp; I also fixed a number of bugs in Invoke-Elevated (alias su), Set-Writable, Edit-File and type accelerators breaking on PowerShell 3.0.</p>
<p>As you use these release candidates please report any issues to the <a href="http://pscx.codeplex.com/workitem/list/basic">Pscx CodePlex project</a>.&nbsp; Thanks for supporting Pscx!</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/rkeithhill.wordpress.com/271/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/rkeithhill.wordpress.com/271/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=rkeithhill.wordpress.com&#038;blog=18780344&#038;post=271&#038;subd=rkeithhill&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://rkeithhill.wordpress.com/2012/09/15/pscx-2-1-and-3-0-release-candidates-posted/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="http://2.gravatar.com/avatar/bcc517cd604f90500c5dcef5a6ed7f81?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">rkeithhill</media:title>
		</media:content>
	</item>
		<item>
		<title>PSCX 3.0 Beta Released</title>
		<link>http://rkeithhill.wordpress.com/2012/07/26/pscx-3-0-beta-released/</link>
		<comments>http://rkeithhill.wordpress.com/2012/07/26/pscx-3-0-beta-released/#comments</comments>
		<pubDate>Fri, 27 Jul 2012 04:12:31 +0000</pubDate>
		<dc:creator>rkeithhill</dc:creator>
				<category><![CDATA[PowerShell 3.0]]></category>
		<category><![CDATA[PSCX]]></category>

		<guid isPermaLink="false">https://rkeithhill.wordpress.com/?p=268</guid>
		<description><![CDATA[We’ve just released a beta of the PowerShell Community Extensions 3.0 which targets PowerShell 3.0 specifically.&#160; This new version uses a WiX based installer.&#160; We may look at providing an xcopy deployable ZIP file but we had so many users &#8230; <a href="http://rkeithhill.wordpress.com/2012/07/26/pscx-3-0-beta-released/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=rkeithhill.wordpress.com&#038;blog=18780344&#038;post=268&#038;subd=rkeithhill&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>We’ve just released a <a href="http://pscx.codeplex.com/releases/view/91403">beta of the PowerShell Community Extensions 3.0</a> which targets PowerShell 3.0 specifically.&nbsp; This new version uses a WiX based installer.&nbsp; We may look at providing an xcopy deployable ZIP file but we had so many users get burned by not unblocking the ZIP file that the move back to MSI seemed warranted.&nbsp; The MSI really doesn’t do much other than copy files into the Program Files dir and add a path to the PSModulePath environment variable.&nbsp; </p>
<p>Be sure to read the installation notes on the download page.&nbsp; If you’re having problems importing the PSCX module, you might need to reboot.&nbsp; Yeah I know that sucks but either WiX 3.6 just isn’t handling environment variable updates quite right or I’m not using WiX right.&nbsp; </p>
<p>If you’re using PSCX and Windows PowerShell 3.0, please take this version for a spin.&nbsp; You can use it side-by-side with your current version of PSCX 2.x.&nbsp; When you import PSCX specify the RequiredVersion parameter as shown below e.g.:</p>
<p><font face="Consolas">Import-Module pscx –RequiredVersion 3.0.0.0</font></p>
<p>And please, <a href="http://pscx.codeplex.com/workitem/list/basic">report problems back to the CodePlex site</a>.&nbsp; I haven’t always been able to reply quickly to issues but we do monitor them.&nbsp; Thanks!</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/rkeithhill.wordpress.com/268/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/rkeithhill.wordpress.com/268/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=rkeithhill.wordpress.com&#038;blog=18780344&#038;post=268&#038;subd=rkeithhill&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://rkeithhill.wordpress.com/2012/07/26/pscx-3-0-beta-released/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://2.gravatar.com/avatar/bcc517cd604f90500c5dcef5a6ed7f81?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">rkeithhill</media:title>
		</media:content>
	</item>
		<item>
		<title>PowerShell V3 &#8211; ObsoleteAttribute</title>
		<link>http://rkeithhill.wordpress.com/2012/04/29/powershell-v3-obsoleteattribute/</link>
		<comments>http://rkeithhill.wordpress.com/2012/04/29/powershell-v3-obsoleteattribute/#comments</comments>
		<pubDate>Mon, 30 Apr 2012 04:39:06 +0000</pubDate>
		<dc:creator>rkeithhill</dc:creator>
				<category><![CDATA[PowerShell 3.0]]></category>

		<guid isPermaLink="false">https://rkeithhill.wordpress.com/?p=256</guid>
		<description><![CDATA[PowerShell V3 now supports the ObsoleteAttribute for compiled cmdlets but unfortunately not advanced functions.&#160; This is handy to let your users know that a binary cmdlet will be going away in a future release of your binary module. As we &#8230; <a href="http://rkeithhill.wordpress.com/2012/04/29/powershell-v3-obsoleteattribute/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=rkeithhill.wordpress.com&#038;blog=18780344&#038;post=256&#038;subd=rkeithhill&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>PowerShell V3 now supports the ObsoleteAttribute for compiled cmdlets but unfortunately not advanced functions.&nbsp; This is handy to let your users know that a binary cmdlet will be going away in a future release of your binary module. </p>
<p>As we work on PSCX 3.0 there are a few binary cmdlets that we will mark with this attribute to let you know to switch over to PowerShell’s built-in equivalent before we eliminate the cmdlet completely in the next release.&nbsp; Here’s a snippet that shows how to apply the ObsoleteAttribute in your source code:</p>
<div style="margin:0;display:inline;float:none;padding:0;" id="scid:9D7513F9-C04C-4721-824A-2B34F0212519:3912e6e8-05e0-43c6-a948-981584f74e76" class="wlWriterEditableSmartContent">
<pre style="width:619px;height:194px;background-color:White;overflow:auto;"><div><span style="color:#008080;">1</span> <span style="color:#000000;">[OutputType(</span><span style="color:#0000FF;">typeof</span><span style="color:#000000;">(MailMessage))]
</span><span style="color:#008080;">2</span> <span style="color:#000000;">[Cmdlet(VerbsCommunications.Send, PscxNouns.SmtpMail,
</span><span style="color:#008080;">3</span> <span style="color:#000000;">        DefaultParameterSetName </span><span style="color:#000000;">=</span><span style="color:#000000;"> </span><span style="color:#800000;">&quot;</span><span style="color:#800000;">Authenticated</span><span style="color:#800000;">&quot;</span><span style="color:#000000;">,
</span><span style="color:#008080;">4</span> <span style="color:#000000;">        SupportsShouldProcess </span><span style="color:#000000;">=</span><span style="color:#000000;"> </span><span style="color:#0000FF;">true</span><span style="color:#000000;">)]
</span><span style="color:#008080;">5</span> <span style="color:#000000;">[Obsolete(</span><span style="color:#800000;">@&quot;</span><span style="color:#800000;">The PSCX\SendSmtpMail cmdlet is obsolete </span><span style="color:#800000;">&quot;</span><span style="color:#000000;"> </span><span style="color:#000000;">+</span><span style="color:#000000;">
</span><span style="color:#008080;">6</span> <span style="color:#000000;">           </span><span style="color:#800000;">&quot;</span><span style="color:#800000;">and will removed in the next version of </span><span style="color:#800000;">&quot;</span><span style="color:#000000;"> </span><span style="color:#000000;">+</span><span style="color:#000000;">
</span><span style="color:#008080;">7</span> <span style="color:#000000;">           </span><span style="color:#800000;">&quot;</span><span style="color:#800000;">PSCX. Use the built-in Send-MailMessage.</span><span style="color:#800000;">&quot;</span><span style="color:#000000;">)]
</span><span style="color:#008080;">8</span> <span style="color:#000000;"></span><span style="color:#0000FF;">public</span><span style="color:#000000;"> </span><span style="color:#0000FF;">class</span><span style="color:#000000;"> SendSmtpMailCommand : PscxCmdlet
</span><span style="color:#008080;">9</span> <span style="color:#000000;">{</span></div></pre>
<p><!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --></div>
<p>The resulting of executing this cmdlet with PSCX v3 loaded is:</p>
<div>
<pre style="text-align:left;line-height:14pt;background-color:#000080;margin:0;width:100%;font-family:'Consolas', courier, monospace;direction:ltr;color:white;font-size:10pt;overflow:visible;border-style:none;padding:5px;">C:\PS&gt; Send-SmtpMail
<span style="color:yellow;">WARNING: The PSCX\SendSmtpMail cmdlet is obsolete and will removed in the next version of <br />PSCX. Use the built-in Send-MailMessage.</span></pre>
</div>
<p>There is an ObsoleteAttribute constructor overload that takes a boolean that converts the warning to an error.&nbsp; I’m not sure how useful that is but PowerShell does honor that setting and will generate a terminating error in this case:</p>
<div>
<pre style="text-align:left;line-height:14pt;background-color:#000080;margin:0;width:100%;font-family:'Consolas', courier, monospace;direction:ltr;color:white;font-size:10pt;overflow:visible;border-style:none;padding:5px;">C:\PS&gt; Send-SmtpMail
<span style="color:#ff3f3f;">The PSCX\SendSmtpMail cmdlet is obsolete and will removed in the next version of PSCX. Use <br />the built-in Send-MailMessage.
At line:1 char:1
+ Send-SmtpMail
+ ~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (Send-SmtpMail:String) [], RuntimeException
    + FullyQualifiedErrorId : UseOfDeprecatedCmdlet</span></pre>
</div>
<p>It’s nice to see PowerShell honoring more of the .NET attributes – where it makes sense that is.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/rkeithhill.wordpress.com/256/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/rkeithhill.wordpress.com/256/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=rkeithhill.wordpress.com&#038;blog=18780344&#038;post=256&#038;subd=rkeithhill&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://rkeithhill.wordpress.com/2012/04/29/powershell-v3-obsoleteattribute/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://2.gravatar.com/avatar/bcc517cd604f90500c5dcef5a6ed7f81?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">rkeithhill</media:title>
		</media:content>
	</item>
		<item>
		<title>PowerShell V3 Beta&#8211;Better NTFS Alternate Data Stream Handling</title>
		<link>http://rkeithhill.wordpress.com/2012/03/04/powershell-v3-betabetter-ntfs-alternate-data-stream-handling/</link>
		<comments>http://rkeithhill.wordpress.com/2012/03/04/powershell-v3-betabetter-ntfs-alternate-data-stream-handling/#comments</comments>
		<pubDate>Mon, 05 Mar 2012 04:37:08 +0000</pubDate>
		<dc:creator>rkeithhill</dc:creator>
				<category><![CDATA[PowerShell 3.0]]></category>

		<guid isPermaLink="false">https://rkeithhill.wordpress.com/?p=248</guid>
		<description><![CDATA[One of the many new features in Windows PowerShell V3 is better support for alternate data streams (ADS) in NTFS files.  ADS allows an NTFS file to contain additional data that is not part of the “main” stream i.e. the &#8230; <a href="http://rkeithhill.wordpress.com/2012/03/04/powershell-v3-betabetter-ntfs-alternate-data-stream-handling/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=rkeithhill.wordpress.com&#038;blog=18780344&#038;post=248&#038;subd=rkeithhill&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>One of the many new features in Windows PowerShell V3 is better support for alternate data streams (ADS) in NTFS files.  ADS allows an NTFS file to contain additional data that is not part of the “main” stream i.e. the file’s primary content.  Tools like Windows Explorer or even PowerShell’s <strong>Get-ChildItem</strong> cmdlet don’t show these extra data streams.  In fact the file size reported by both of these tools does not take into account the data stored in the alternate streams.  For more information on ADS check out the <a href="http://en.wikipedia.org/wiki/NTFS#Alternate_data_streams_.28ADS.29">NTFS topic on Wikipedia</a>.</p>
<p>A common use of ADS is to indicate that a file downloaded by Internet Explorer came from the Internet Zone.  Files coming from the internet could be potentially dangerous.  Various applications check for this stream and if it is present and contains information indicating the “Internet” zone, they might block access or in the case of PowerShell’s <em>RemoteSigned</em> execution policy, only execute the file if it is signed.</p>
<p>Previous to PowerShell V3, you could use the <a href="http://technet.microsoft.com/en-us/sysinternals/bb897440">SysInternals streams.exe tool</a> to list and remove alternate data streams.  A common application of this tool was to delete all streams in a file.  That was a rather crude but effective way to “unblock” a file downloaded from the internet.</p>
<p>This is also one area where CMD.EXE was one up on PowerShell.  From a CMD prompt, you can use &#8220;dir /r&#8221; to list files and their alternate data streams.  You can also create/overwrite streams with CMD.exe like so “<span style="font-family:Consolas;">echo.&gt;test.exe:Zone.Identifier</span>” which would “unblock” an internet zone file.  You can also unblock such files by selecting the file’s Properties in Windows Explorer and pressing the “Unblock” button at the bottom right of the general tab.  However this is not convenient if you need to do this to dozens or hundreds of files.  With the <a href="http://pscx.codeplex.com/">PowerShell Community Extensions</a> 2.0, we introduced an <strong>Unblock-File</strong> cmdlet that would delete only the stream named Zone.Identifier.  That is the stream that Internet Explorer creates when you download a file.  Fortunately with PowerShell V3, we can obsolete that cmdlet because V3 offers several ways to manage alternate data streams.</p>
<p>First up is PowerShell’s own <strong>Unblock-File</strong> cmdlet which, like the PSCX equivalent, is quite easy to use:</p>
<pre style="font-size:10pt;font-family:consolas, courier, monospace;width:100%;color:white;overflow:visible;direction:ltr;text-align:left;line-height:14pt;background-color:#000080;border-style:none;margin:0;padding:5px;">C:\PS&gt; Get-Command Unblock-File -All

Capability      Name   ModuleName
----------      ----                                     ----------
Cmdlet          Unblock-File                             Pscx
Cmdlet          Unblock-File                             Microsoft.PowerShell.Utility

C:\PS&gt; Get-ChildItem *.ps1 | Microsoft.PowerShell.Utility\Unblock-File</pre>
<p>Note that you wouldn’t normally need to prefix <strong>Unblock-File</strong> with <em>Microsoft.PowerShell.Utility</em>.  In this case, I wanted to make sure I was using the PowerShell <strong>Unblock-File</strong> and not the one from PSCX.</p>
<p>In addition to using the big gun of <strong>Unblock-File</strong> you can also manipulate streams with the following cmdlets:</p>
<pre style="font-size:10pt;font-family:consolas, courier, monospace;width:100%;color:white;overflow:visible;direction:ltr;text-align:left;line-height:14pt;background-color:#000080;border-style:none;margin:0;padding:5px;">C:\PS&gt; Get-Command -ParameterName Stream | Where ModuleName -match 'Microsoft.*?Manag' 

Capability Name          ModuleName
---------- ----          ----------
Cmdlet     Add-Content   Microsoft.PowerShell.Management
Cmdlet     Clear-Content Microsoft.PowerShell.Management
Cmdlet     Get-Content   Microsoft.PowerShell.Management
Cmdlet     Get-Item      Microsoft.PowerShell.Management
Cmdlet     Remove-Item   Microsoft.PowerShell.Management
Cmdlet     Set-Content   Microsoft.PowerShell.Management</pre>
<p>Here is how you can list all the alternate data streams in a file and the contents of any particular data stream:</p>
<pre style="font-size:10pt;font-family:consolas, courier, monospace;width:100%;color:white;overflow:visible;direction:ltr;text-align:left;line-height:14pt;background-color:#000080;border-style:none;margin:0;padding:5px;">C:\PS&gt; Get-Item .\Pscx-2.0.0.1.zip -Stream *

   FileName: C:\Users\Keith\Downloads\Pscx-2.0.0.1.zip

Stream                   Length
------                   ------
:$DATA                  1799345
Zone.Identifier              26

C:\PS&gt; Get-Content .\Pscx-2.0.0.1.zip -Stream Zone.Identifier
[ZoneTransfer]
ZoneId=3</pre>
<p>Note that <strong>:$DATA</strong> is the main stream i.e. the file’s primary contents.</p>
<p>If you need to clear the contents of a data stream without removing the stream completely, you can use <strong>Clear-Content’s –Stream</strong> parameter e.g.:</p>
<pre style="font-size:10pt;font-family:consolas, courier, monospace;width:100%;color:white;overflow:visible;direction:ltr;text-align:left;line-height:14pt;background-color:#000080;border-style:none;margin:0;padding:5px;">C:\PS&gt; Clear-Content .\Pscx-2.0.0.1.zip -Stream Zone.Identifier
C:\PS&gt; Get-Content .\Pscx-2.0.0.1.zip -Stream Zone.Identifier
C:\PS&gt; Get-Item .\Pscx-2.0.0.1.zip -Stream *

   FileName: C:\Users\Keith\Downloads\Pscx-2.0.0.1.zip

Stream                   Length
------                   ------
:$DATA                  1799345
Zone.Identifier               0</pre>
<p>To completely remove the stream, use <strong>Remove-Item’s –Stream</strong> parameter e.g.:</p>
<pre style="font-size:10pt;font-family:consolas, courier, monospace;width:100%;color:white;overflow:visible;direction:ltr;text-align:left;line-height:14pt;background-color:#000080;border-style:none;margin:0;padding:5px;">C:\PS&gt; Remove-Item .\Pscx-2.0.0.1.zip -Stream Zone.Identifier
C:\PS&gt; Get-Item .\Pscx-2.0.0.1.zip -Stream *

   FileName: C:\Users\Keith\Downloads\Pscx-2.0.0.1.zip

Stream                   Length
------                   ------
:$DATA                  1799345</pre>
<p>And if you need to create an alternate stream, you can do so using <strong>Add-Content’s –Stream</strong> parameter e.g.:</p>
<pre style="font-size:10pt;font-family:consolas, courier, monospace;width:100%;color:white;overflow:visible;direction:ltr;text-align:left;line-height:14pt;background-color:#000080;border-style:none;margin:0;padding:5px;">C:\PS&gt; Add-Content Pscx-2.0.0.1.zip -Str Zone.Identifier "[ZoneTransfer]`r`nZoneId=3"
C:\PS&gt; Get-Item Pscx-2.0.0.1.zip -Stream *

   FileName: C:\Users\Keith\Downloads\Pscx-2.0.0.1.zip

Stream                   Length
------                   ------
:$DATA                  1799345
Zone.Identifier              26

C:\PS&gt; Get-Content .\Pscx-2.0.0.1.zip -Stream Zone.Identifier
[ZoneTransfer]
ZoneId=3</pre>
<p>Finally, <strong>Set-Content –Stream </strong>can be used to modify the content of an existing stream.</p>
<p>The new  <strong>Unblock-File</strong> cmdlet as well as the upgrades to the <strong>*-Content</strong> and <strong>Get/Remove-Item</strong>  cmdlets are a very welcome enhancement to PowerShell’s file handling capabilities.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/rkeithhill.wordpress.com/248/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/rkeithhill.wordpress.com/248/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=rkeithhill.wordpress.com&#038;blog=18780344&#038;post=248&#038;subd=rkeithhill&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://rkeithhill.wordpress.com/2012/03/04/powershell-v3-betabetter-ntfs-alternate-data-stream-handling/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
	
		<media:content url="http://2.gravatar.com/avatar/bcc517cd604f90500c5dcef5a6ed7f81?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">rkeithhill</media:title>
		</media:content>
	</item>
		<item>
		<title>PowerShell V3 CTP2 Provides Better Argument Passing to EXEs</title>
		<link>http://rkeithhill.wordpress.com/2012/01/02/powershell-v3-ctp2-provides-better-argument-passing-to-exes/</link>
		<comments>http://rkeithhill.wordpress.com/2012/01/02/powershell-v3-ctp2-provides-better-argument-passing-to-exes/#comments</comments>
		<pubDate>Mon, 02 Jan 2012 19:56:23 +0000</pubDate>
		<dc:creator>rkeithhill</dc:creator>
				<category><![CDATA[PowerShell 3.0]]></category>
		<category><![CDATA[Parsing]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[V3]]></category>

		<guid isPermaLink="false">https://rkeithhill.wordpress.com/?p=241</guid>
		<description><![CDATA[Within PowerShell it has always been easy to pass “simple” arguments to an EXE e.g.: C:\PS&#62; ipconfig -all However passing arguments to certain exes can become surprising difficult when their command line parameter syntax is complex i.e. they require quotes &#8230; <a href="http://rkeithhill.wordpress.com/2012/01/02/powershell-v3-ctp2-provides-better-argument-passing-to-exes/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=rkeithhill.wordpress.com&#038;blog=18780344&#038;post=241&#038;subd=rkeithhill&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>Within PowerShell it has always been easy to pass “simple” arguments to an EXE e.g.:</p>
<div>
<pre style="text-align:left;line-height:14pt;background-color:#000080;width:100%;font-family:Consolas, courier, monospace;direction:ltr;color:white;font-size:10pt;overflow:visible;border-style:none;margin:0;padding:5px;">C:\PS&gt; ipconfig -all</pre>
</div>
<p>However passing arguments to certain exes can become surprising difficult when their command line parameter syntax is complex i.e. they require quotes and use special PowerShell characters such as @ $ ;.  A lot of these problems can be solved by placing single or double quotes in the right places or by escaping PowerShell’s special characters e.g.:</p>
<div>
<pre style="text-align:left;line-height:14pt;background-color:#000080;width:100%;font-family:Consolas, courier, monospace;direction:ltr;color:white;font-size:10pt;overflow:visible;border-style:none;margin:0;padding:5px;">C:\PS&gt; tf.exe status . /workspace:HILLR1;hillr /r
There are no pending changes.
The term 'hillr' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the
spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:35
+ tf.exe status . /workspace:HILLR1;hillr /r
+                                   ~~~~~
    + CategoryInfo          : ObjectNotFound: (hillr:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException</pre>
</div>
<div></div>
<p>Note that in the command line above the “/workspace” parameter value is specified using a special syntax that TF.exe recognizes i.e. &lt;workspace_name&gt;;&lt;username&gt;.  Unfortunately the semicolon is a statement separator in PowerShell which means that TF.exe only sees the parameters before the semicolon.  We can use the ECHOARGS.exe utility from the <a href="http://pscx.codeplex.com/">PowerShell Community Extensions</a> to verify this:</p>
<div>
<pre style="text-align:left;line-height:14pt;background-color:#000080;width:100%;font-family:Consolas, courier, monospace;direction:ltr;color:white;font-size:10pt;overflow:visible;border-style:none;margin:0;padding:5px;">C:\PS&gt; echoargs.exe status . /workspace:HILLR1;hillr /r
Arg 0 is &lt;status&gt;
Arg 1 is &lt;.&gt;
Arg 2 is &lt;/workspace:HILLR1&gt;</pre>
</div>
<p>In this case, the solution is simple – just escape the semicolon e.g.:</p>
<div>
<pre style="text-align:left;line-height:14pt;background-color:#000080;width:100%;font-family:Consolas, courier, monospace;direction:ltr;color:white;font-size:10pt;overflow:visible;border-style:none;margin:0;padding:5px;">C:\PS&gt; tf.exe status . /r /workspace:HILLR1`;hillr
File name     Change Local path
------------- ------ -----------------------------------------
$/Foo/Trunk/Tools/Bin
TfsTools.psm1 edit   C:\Tfs\Foo\Trunk\Tools\Bin\TfsTools.psm1

1 change(s)</pre>
</div>
<p>This works up to the point where you get quite frustrated figuring out which characters to escape and which parameter/argument pairs need to be quoted and whether you should use single quotes or double quotes.  Fortunately, it looks like we will get a way to tell the PowerShell argument parser to stop doing so much work for us and just pass the args through “as-is”.  In other words, you can tell PowerShell to become a “dumber” command line parser.  This mode is invoked using the character sequence: –% and it works from the point it appears on the command line to the end of that line.  Note that the character sequence may change or the feature could be completely removed before V3 ships.</p>
<p>Given this new feature, here’s how you use it.  Take this example of a problematic set of command line parameters:</p>
<div>
<pre style="text-align:left;line-height:14pt;background-color:#000080;width:100%;font-family:Consolas, courier, monospace;direction:ltr;color:white;font-size:10pt;overflow:visible;border-style:none;margin:0;padding:5px;">C:\PS&gt; sqlcmd -S .\SQLEXPRESS -v lname="Gates" -Q "SELECT FirstName,LastName FROM
AdventureWorks.Person.Contact WHERE LastName = '$(lname)'"
The term 'lname' is not recognized as the name of a cmdlet, function, script
file, or operable program. Check the spelling of the name, or if a path was
included, verify that the path is correct and try again.
At line:1 char:126
+ ...  LastName = '$(lname)'"
+                    ~~~~~
    + CategoryInfo          : ObjectNotFound: (lname:String) [], CommandNotFou
   ndException
    + FullyQualifiedErrorId : CommandNotFoundException</pre>
<p>In this case the V2 solution is to escape the $ character in the last part of the command line e.g.: &#8216;`$(lname)&#8217; but if you don’t want to spend the time to figure this out you can easily use &#8211;% like so:</p>
</div>
<div>
<pre style="text-align:left;line-height:14pt;background-color:#000080;width:100%;font-family:Consolas, courier, monospace;direction:ltr;color:white;font-size:10pt;overflow:visible;border-style:none;margin:0;padding:5px;">C:\PS&gt; sqlcmd --% -S .\SQLEXPRESS -v lname="Gates" -Q "SELECT FirstName,LastName F
ROM AdventureWorks.Person.Contact WHERE LastName = '$(lname)'"
FirstName                                          LastName

---------------------------------- -----------------------------------
Janet                              Gates

(1 rows affected)</pre>
</div>
<p>You can put the &#8211;% later in the parameter list if you want.  You might want to do this if you need to use PowerShell variable expansion in some of the arguments.  Just note that once you specify &#8211;% the rest of the command line will be parsed “dumbly”.  You will get no PowerShell variable expansion or grouping expressions and you won’t be able to escape newlines.  One thing you can do in this special parsing mode is expand environment variables using the batch syntax of %ENV_VAR% e.g.:</p>
<div>
<pre style="text-align:left;line-height:14pt;background-color:#000080;width:100%;font-family:Consolas, courier, monospace;direction:ltr;color:white;font-size:10pt;overflow:visible;border-style:none;margin:0;padding:5px;">C:\PS&gt; $env:colname = "LastName"
C:\PS&gt; sqlcmd -S .\SQLEXPRESS -v lname="Gates" --% -Q "SELECT FirstName,LastName F
ROM AdventureWorks.Person.Contact WHERE %colname% = '$(lname)'"
FirstName                                          LastName

---------------------------------- -----------------------------------
Janet                              Gates

(1 rows affected)</pre>
<p>I believe this new command line parsing feature will greatly simplify interacting with exes that have a complex command line parameter syntax.  Thanks to the PowerShell team for listening to the <a href="https://connect.microsoft.com/PowerShell/feedback/details/376207/executing-commands-which-require-quotes-and-variables-is-practically-impossible">community feedback on this issue</a> and providing a solution.</p>
</div>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/rkeithhill.wordpress.com/241/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/rkeithhill.wordpress.com/241/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=rkeithhill.wordpress.com&#038;blog=18780344&#038;post=241&#038;subd=rkeithhill&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://rkeithhill.wordpress.com/2012/01/02/powershell-v3-ctp2-provides-better-argument-passing-to-exes/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
	
		<media:content url="http://2.gravatar.com/avatar/bcc517cd604f90500c5dcef5a6ed7f81?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">rkeithhill</media:title>
		</media:content>
	</item>
		<item>
		<title>Microsoft Windows PowerShell V3 CTP2 Available for Download</title>
		<link>http://rkeithhill.wordpress.com/2011/12/05/microsoft-windows-powershell-v3-ctp2-available-for-download/</link>
		<comments>http://rkeithhill.wordpress.com/2011/12/05/microsoft-windows-powershell-v3-ctp2-available-for-download/#comments</comments>
		<pubDate>Mon, 05 Dec 2011 17:40:24 +0000</pubDate>
		<dc:creator>rkeithhill</dc:creator>
				<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[PowerShell 3.0]]></category>

		<guid isPermaLink="false">https://rkeithhill.wordpress.com/?p=238</guid>
		<description><![CDATA[You can grab the bits from here. If you have V3 CTP1 installed, please uninstall it first or you can get your machine into a bad state. So far my favorite two features new to this drop are both in &#8230; <a href="http://rkeithhill.wordpress.com/2011/12/05/microsoft-windows-powershell-v3-ctp2-available-for-download/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=rkeithhill.wordpress.com&#038;blog=18780344&#038;post=238&#038;subd=rkeithhill&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>You can grab the bits from <a href="http://www.microsoft.com/download/en/details.aspx?id=27548">here</a>. <font>If you have V3 CTP1 installed,</font><font> </font><font>please uninstall it first or you can get your machine into a bad state</font>. </p>
<p>So far my favorite two features new to this drop are both in the Integrated Scripting Editor (ISE). The first is the “most recently opened files list” on the File menu and second is the switch to a two pane ISE (combines the output and command panes into one). Oh yeah, there isn’t much in the help system until you run Update-Help from an elevated prompt.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/rkeithhill.wordpress.com/238/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/rkeithhill.wordpress.com/238/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=rkeithhill.wordpress.com&#038;blog=18780344&#038;post=238&#038;subd=rkeithhill&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://rkeithhill.wordpress.com/2011/12/05/microsoft-windows-powershell-v3-ctp2-available-for-download/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://2.gravatar.com/avatar/bcc517cd604f90500c5dcef5a6ed7f81?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">rkeithhill</media:title>
		</media:content>
	</item>
		<item>
		<title>Windows PowerShell Version 3 Simplified Syntax</title>
		<link>http://rkeithhill.wordpress.com/2011/10/19/windows-powershell-version-3-simplified-syntax/</link>
		<comments>http://rkeithhill.wordpress.com/2011/10/19/windows-powershell-version-3-simplified-syntax/#comments</comments>
		<pubDate>Thu, 20 Oct 2011 00:44:42 +0000</pubDate>
		<dc:creator>rkeithhill</dc:creator>
				<category><![CDATA[PowerShell 3.0]]></category>

		<guid isPermaLink="false">https://rkeithhill.wordpress.com/2011/10/19/windows-powershell-version-3-simplified-syntax/</guid>
		<description><![CDATA[Windows PowerShell version 3 introduces a simplified syntax for the Where-Object and Foreach-Object cmdlets.&#160; The simplified syntax shown below, eliminates the curly braces as well as the need for the special variable $_. C:\PS&#62; Get-Process &#124; Where PM -gt 100MB &#8230; <a href="http://rkeithhill.wordpress.com/2011/10/19/windows-powershell-version-3-simplified-syntax/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=rkeithhill.wordpress.com&#038;blog=18780344&#038;post=233&#038;subd=rkeithhill&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>Windows PowerShell version 3 introduces a simplified syntax for the Where-Object and Foreach-Object cmdlets.&nbsp; The simplified syntax shown below, eliminates the curly braces as well as the need for the special variable <font face="Consolas">$_</font>.</p>
<div id="codeSnippetWrapper">
<div id="codeSnippetWrapper">
<div>
<pre style="text-align:left;line-height:14pt;background-color:#000080;width:100%;font-family:Consolas, courier, monospace;direction:ltr;color:white;font-size:10pt;overflow:visible;border-style:none;margin:0;padding:5px;">C:\PS&gt; Get-Process | Where PM -gt 100MB
...
C:\PS&gt; Get-Process | Foreach Name
...</pre>
</div>
<p></div>
</div>
<p>The intent of this “syntax” is to make it easier for folks get started with PowerShell.&nbsp; Compared to the commands below, I can see the value of the simplified syntax:</p>
<div id="codeSnippetWrapper">
<div id="codeSnippetWrapper">
<div>
<pre style="text-align:left;line-height:14pt;background-color:#000080;width:100%;font-family:Consolas, courier, monospace;direction:ltr;color:white;font-size:10pt;overflow:visible;border-style:none;margin:0;padding:5px;">C:\PS&gt; Get-Process | Where {$_.PM -gt 100MB}
...
C:\PS&gt; Get-Process | Foreach {$_.Name}
...</pre>
</div>
<p></div>
</div>
<p>When folks are first learning PowerShell, the special variable <font face="Consolas">$_</font> is one of those mental model hurdles they have to get over.&nbsp; The simplified syntax feature of V3 seems to generate a fair amount of controversy (is it really necessary, doesn’t this just complicate things more, etc).&nbsp; Regardless of where you stand on the simplified syntax it is useful to understand how it works.</p>
<p>Given that it appears to be a simplified expression syntax you might think this required a change to the PowerShell parser’s grammar but you would be wrong.&nbsp; It turns out that the simplified syntax is implemented by additional parameter sets – lots of additional parameter sets. In fact, for every operator supported, there is an additional parameter set to support that operator.&nbsp; Let’s see this with the Where-Object cmdlet by listing out all of its parameter set names:</p>
<div>
<pre style="text-align:left;line-height:14pt;background-color:#000080;width:100%;font-family:Consolas, courier, monospace;direction:ltr;color:white;font-size:10pt;overflow:visible;border-style:none;margin:0;padding:5px;">C:\PS&gt; Get-Command Where-Object | Select -Expand ParameterSets | Format-Table Name

Name
----
EqualSet
ScriptBlockSet
CaseSensitiveGreaterThanSet
CaseSensitiveNotEqualSet
LessThanSet
CaseSensitiveEqualSet
NotEqualSet
GreaterThanSet
CaseSensitiveLessThanSet
GreaterOrEqualSet
CaseSensitiveGreaterOrEqualSet
LessOrEqualSet
CaseSensitiveLessOrEqualSet
LikeSet
CaseSensitiveLikeSet
NotLikeSet
CaseSensitiveNotLikeSet
MatchSet
CaseSensitiveMatchSet
NotMatchSet
CaseSensitiveNotMatchSet
ContainsSet
CaseSensitiveContainsSet
NotContainsSet
CaseSensitiveNotContainsSet
InSet
CaseSensitiveInSet
NotInSet
CaseSensitiveNotInSet
IsSet
IsNotSet</pre>
</div>
<div id="codeSnippetWrapper">
<div id="codeSnippetWrapper">
<div>&nbsp;</div>
</div>
</div>
<p>Most of these correspond to the operators you are already familiar with such as: –GT, –LT, –GE, –LE, –LIKE, –MATCH, –NOTMATCH, –CONTAINS, –NOTCONTAINS, etc.&nbsp; Note however there are two new operators in PowerShell V3: –In and –NotIn which you can use like so:</p>
<div id="codeSnippetWrapper">
<div>
<pre style="text-align:left;line-height:14pt;background-color:#000080;width:100%;font-family:Consolas, courier, monospace;direction:ltr;color:white;font-size:10pt;overflow:visible;border-style:none;margin:0;padding:5px;">C:\PS&gt; 1 -In 1..10
True
C:\PS&gt; 20 -NotIn 1..10
True</pre>
</div>
<p></div>
<p>Let’s look at the interesting parameters on these operator specific parameter sets.&nbsp; Let’s look at the EqualsSet parameter set:</p>
<div id="codeSnippetWrapper">
<div>
<pre style="text-align:left;line-height:14pt;background-color:#000080;width:100%;font-family:Consolas, courier, monospace;direction:ltr;color:white;font-size:10pt;overflow:visible;border-style:none;margin:0;padding:5px;">C:\PS&gt; Get-Command Where-Object | Select -Expand ParameterSets | Where Name -eq EqualSet | 
           Select -Expand Parameters | Where Position -ge 0 | 
           Format-Table Name,Position,IsMandatory -AutoSize
    
Name     Position IsMandatory
----     -------- -----------
Property        0        True
Value           1       False</pre>
</div>
<p></div>
<p>As it turns out, these results are the same for all the <em>operator</em> oriented parameter sets.&nbsp; At the very minimum, the Property parameter is required and is always the first positional parameter.&nbsp; And as you would expect, if you don’t provide it, you get prompted for a value:</p>
<div id="codeSnippetWrapper">
<div>
<pre style="text-align:left;line-height:14pt;background-color:#000080;width:100%;font-family:Consolas, courier, monospace;direction:ltr;color:white;font-size:10pt;overflow:visible;border-style:none;margin:0;padding:5px;">C:\PS&gt; Get-Process | Where -eq

cmdlet Where-Object at command pipeline position 2
Supply values for the following parameters:
Property:</pre>
</div>
<p></div>
<p>Now even though Value parameter is specified as not mandatory, in many cases if you don’t provide it you will get a terminating error e.g.:</p>
<div id="codeSnippetWrapper">
<div>
<pre style="text-align:left;line-height:14pt;background-color:#000080;width:100%;font-family:Consolas, courier, monospace;direction:ltr;color:white;font-size:10pt;overflow:visible;border-style:none;margin:0;padding:5px;">C:\PS&gt; Get-Process | Where Name -eq
Where-Object : The specified operator requires both the -Property and -Value parameters. Supply both parameters and
retry.
At line:1 char:15
+ Get-Process | Where Name -eq
+               ~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [Where-Object], PSArgumentException
    + FullyQualifiedErrorId : ValueNotSpecifiedForWhereObject,Microsoft.PowerShell.Commands.WhereObjectCommand</pre>
</div>
<p></div>
<p>There are some cases where you don’t have to provide the value nor the operator e.g.:</p>
<div id="codeSnippetWrapper">
<div>
<pre style="text-align:left;line-height:14pt;background-color:#000080;width:100%;font-family:Consolas, courier, monospace;direction:ltr;color:white;font-size:10pt;overflow:visible;border-style:none;margin:0;padding:5px;">C:\PS&gt; Get-Process | Where Responding

Handles  NPM(K)    PM(K)      WS(K) VM(M)   CPU(s)     Id ProcessName
-------  ------    -----      ----- -----   ------     -- -----------
    216      10     3560       2896    73            4000 atieclxx
    130       7     2380       1028    33            1020 atiesrxx
    157      11    17288      13344    49            7876 audiodg
     28       6     1256        420    42     0.06   2752 BluetoothHeadsetProxy
...</pre>
</div>
<p></div>
<p>This works because A) the EqualsSet parameter set is the default parameter set and B) the Where-Object implementation appears to coerce the property specified (<em>Responding</em> in this case) to Boolean. If the result is $true then the object is output by Where-Object and sent on its way down the pipeline.</p>
<p>So all this simplified syntax really is, is a bunch of operator specific parameter sets on Where-Object that have a positional and mandatory Property parameter of type [string] and a positional Value parameter of type [object].&nbsp; In the case of Foreach-Object it is one extra parameter set called PropertyAndMethodSet which has one mandatory, positional parameter called MemberName.&nbsp; And as with any cmdlet, you provide the parameter values and the cmdlet determines how to interpret them.&nbsp; In fact, given standard parameter parsing behavior the below is as valid as the conventional notation:</p>
<div id="codeSnippetWrapper">
<div>
<pre style="text-align:left;line-height:14pt;background-color:#000080;width:100%;font-family:Consolas, courier, monospace;direction:ltr;color:white;font-size:10pt;overflow:visible;border-style:none;margin:0;padding:5px;">C:\PS&gt; Get-Process | Where -GT PM 100MB
...
C:\PS&gt; Get-Process | Where PM 100MB -GT
...
C:\PS&gt; Get-Process | Where -Value 100MB -Property PM -GT
...</pre>
</div>
<p></div>
<div>Now where this syntax can lead you astray if you don’t understand how it works, is if you make the assumption that this is a parsed expression.&nbsp; In that case, folks might expect this to work:</div>
<div>&nbsp;</div>
<div id="codeSnippetWrapper">
<div>
<pre style="text-align:left;line-height:14pt;background-color:#000080;width:100%;font-family:Consolas, courier, monospace;direction:ltr;color:white;font-size:10pt;overflow:visible;border-style:none;margin:0;padding:5px;">C:\PS&gt; Get-Process | Where Threads.Count -GT 100</pre>
</div>
<p></div>
<div>There <em>is</em> a Threads collection on each Process object.&nbsp; We might think that we can access a property on that collection but in effect, what happens is that the Where-Object Property parameter gets the value “Threads.Count” and there is no property on a Process object called “Threads.Count”. This silently fails which might lead you to believe there are no processes with greater than 100 threads.&nbsp; But reverting back to the standard syntax we see that isn’t the case:</div>
<div>&nbsp;</div>
<div id="codeSnippetWrapper">
<div>
<pre style="text-align:left;line-height:14pt;background-color:#000080;width:100%;font-family:Consolas, courier, monospace;direction:ltr;color:white;font-size:10pt;overflow:visible;border-style:none;margin:0;padding:5px;">C:\PS&gt; Get-Process | Where {$_.Threads.Count -GT 100}

Handles  NPM(K)    PM(K)      WS(K) VM(M)   CPU(s)     Id ProcessName
-------  ------    -----      ----- -----   ------     -- -----------
   2080     126   155680     139928   531   113.68   4920 msnmsgr
   1087       0      312       8800    15               4 System</pre>
</div>
<p></div>
<div>So when you are using the simplified syntax be sure to keep in mind that you can <strong>only </strong>specify property names and you cannot access sub-properties.&nbsp; Keep your property names simple and you should be copasetic with the new, simplified syntax.&nbsp; While I’m a little unsure about the new simplified syntax given how quickly you can fall off the “simple” path into the sharp rocks and lava below, I will say this.&nbsp; As I wrote this blog post, I used the simplified syntax quite a bit and I have to say that it is growing on me.</div>
<div>&nbsp;</div>
<div>One final item to mention about simplified syntax.&nbsp; It turns out that some folks have a hard time grokking <font face="Consolas">$_</font> but when they’re presented with <font face="Consolas"><strong>$PSItem</strong></font> it apparently makes more sense to them.&nbsp; So in PowerShell v3, wherever you can use <font face="Consolas">$_</font> you can also use <font face="Consolas">$PSItem</font>.&nbsp; <font face="Consolas">$PSItem</font> is not an alias. It seems to be a duplicate variable defined in all the same scopes as <font face="Consolas">$_</font> and its value tracks that of <font face="Consolas">$_</font> e.g.:</div>
<div>&nbsp;</div>
<div>
<pre style="text-align:left;line-height:14pt;background-color:#000080;width:100%;font-family:Consolas, courier, monospace;direction:ltr;color:white;font-size:10pt;overflow:visible;border-style:none;margin:0;padding:5px;">C:\PS&gt; 1 | Foreach {Get-Variable _,psitem; $_ = 4; Get-Variable _,psitem}

Name                           Value
----                           -----
_                              1
PSItem                         1
_                              4
PSItem                         4</pre>
</div>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/rkeithhill.wordpress.com/233/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/rkeithhill.wordpress.com/233/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=rkeithhill.wordpress.com&#038;blog=18780344&#038;post=233&#038;subd=rkeithhill&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://rkeithhill.wordpress.com/2011/10/19/windows-powershell-version-3-simplified-syntax/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
	
		<media:content url="http://2.gravatar.com/avatar/bcc517cd604f90500c5dcef5a6ed7f81?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">rkeithhill</media:title>
		</media:content>
	</item>
	</channel>
</rss>
