<?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>Get-PowerShell &#187; bug</title>
	<atom:link href="http://get-powershell.com/category/bug/feed/" rel="self" type="application/rss+xml" />
	<link>http://get-powershell.com</link>
	<description></description>
	<lastBuildDate>Sat, 10 Jul 2010 15:44:01 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Inconsistency about parsing Mandatory Parameters</title>
		<link>http://get-powershell.com/2009/04/10/inconsistency-about-parsing-mandatory-parameters/</link>
		<comments>http://get-powershell.com/2009/04/10/inconsistency-about-parsing-mandatory-parameters/#comments</comments>
		<pubDate>Fri, 10 Apr 2009 15:37:41 +0000</pubDate>
		<dc:creator>Andy Schneider</dc:creator>
				<category><![CDATA[Mandatory Parameter]]></category>
		<category><![CDATA[Powershell]]></category>
		<category><![CDATA[bug]]></category>

		<guid isPermaLink="false">http://get-powershell.com/2009/04/10/inconsistency-about-parsing-mandatory-parameters/</guid>
		<description><![CDATA[Yesterday, I came across what I thought was a bug in PowerShell. Consider the following function: Function Demo { param([parameter(mandatory=$true)][int64]$size) $size } This seems quite basic. It simply returns the argument that you enter for size. 75 &#62;&#160; demo 5 5 Now if you don’t provide a value you will get a prompt,and in ISE [...]]]></description>
			<content:encoded><![CDATA[<p>Yesterday, I came across what I thought was a bug in PowerShell. Consider the following function:</p>
<pre class="PowerShellColorizedScript"><span style="color: #00008b">Function</span> <span style="color: #8a2be2">Demo</span> <span style="color: #000000">{</span>
<span style="color: #00008b">param</span><span style="color: #000000">(</span><span style="color: #a9a9a9">[</span><span style="color: #add8e6">parameter</span><span style="color: #000000">(</span><span style="color: #000000">mandatory</span><span style="color: #a9a9a9">=</span><span style="color: #ff4500">$true</span><span style="color: #000000">)</span><span style="color: #a9a9a9">]</span><span style="color: #008080">[int64]</span><span style="color: #ff4500">$size</span><span style="color: #000000">)</span>
<span style="color: #ff4500">$size</span>
<span style="color: #000000">}</span>            </pre>
<p>This seems quite basic. It simply returns the argument that you enter for size. </p>
<p>75 &gt;&#160; demo 5<br />
  <br />5</p>
<p>Now if you don’t provide a value you will get a prompt,and in ISE it will prompt like this</p>
<p><a href="http://get-powershell.com/wp-content/uploads/2009/04/image.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://get-powershell.com/wp-content/uploads/2009/04/image-thumb.png" width="463" height="134" /></a> </p>
<p>and you get the following output</p>
<p>77 &gt;&#160; demo<br />
  <br />20</p>
<p>Simple stuff so far. But now, check this out. PS has some built in shortcuts for KB,MB,GB, and TB</p>
<p>79 &gt;&#160; 1mb<br />
  <br />1048576</p>
<p>So now we can do Demo 20MB and get the following</p>
<p>82 &gt;&#160; Demo 20MB<br />
  <br />20971520</p>
<p>However, if we just run Demo with no parameters and get prompted as before, we get an error if we enter 20MB</p>
<p>83 &gt;&#160; demo<br />
  <br /><font color="#ff0000">Demo : Cannot process argument transformation on parameter &#8216;size&#8217;. Cannot convert value &quot;20MB&quot; to type &quot;System.Int64&quot;.</font></p>
<p>The PowerShell Team closed <a href="https://connect.microsoft.com/feedback/ViewFeedback.aspx?FeedbackID=431621&amp;SiteID=99">my bug</a> on this and marked it “By Design.” The reasoning is around security with the following explanation:</p>
<p>“The prompting mechanism is inherently insecure and we do not want to introduce a code execution bug similar to the mailer bug in the old ATT UnixPC. If the user is running an application elevated which uses script and an error results in a prompt, the user&#8217;s ability to exploit that prompt should be as restricted as possible.”</p>
<p>That is fine, but my issue is that this provides an inconsistent user experience. I would think that typing a parameter argument or entering one from an input box should provide the same result. Maybe both should error out.</p>
]]></content:encoded>
			<wfw:commentRss>http://get-powershell.com/2009/04/10/inconsistency-about-parsing-mandatory-parameters/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
