<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.technet.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Build Your Own PowerShell Cmdlet: Part 4 of 9</title><link>http://blogs.technet.com/b/heyscriptingguy/archive/2012/10/02/build-your-own-powershell-cmdlet-part-4-of-9.aspx</link><description>Microsoft Windows PowerShell MVP, Sean Kearney, continues a series of guest blogs that detail how to build your own cmdlet.</description><dc:language>en-US</dc:language><generator>Telligent Evolution Platform Developer Build (Build: 5.6.50428.7875)</generator><item><title>re: Build Your Own PowerShell Cmdlet: Part 4 of 9</title><link>http://blogs.technet.com/b/heyscriptingguy/archive/2012/10/02/build-your-own-powershell-cmdlet-part-4-of-9.aspx#3524015</link><pubDate>Wed, 03 Oct 2012 18:49:13 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:3524015</guid><dc:creator>Sean Kearney (The Energized Tech)</dc:creator><description>&lt;p&gt;I believe that all picks up tomorrow when &amp;quot;Begin, Process and End&amp;quot; blocks are used. &amp;nbsp; You&amp;#39;ll find this really useful when you read the entire series end to end. &amp;nbsp;Almost like a Chapter from a book :)&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.technet.com/aggbug.aspx?PostID=3524015" width="1" height="1"&gt;</description></item><item><title>re: Build Your Own PowerShell Cmdlet: Part 4 of 9</title><link>http://blogs.technet.com/b/heyscriptingguy/archive/2012/10/02/build-your-own-powershell-cmdlet-part-4-of-9.aspx#3523822</link><pubDate>Tue, 02 Oct 2012 18:26:20 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:3523822</guid><dc:creator>PoSHV</dc:creator><description>&lt;p&gt;I think i have same problem as Morimu36. No matter what parameters i give, it keep saying file already exists :(&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.technet.com/aggbug.aspx?PostID=3523822" width="1" height="1"&gt;</description></item><item><title>re: Build Your Own PowerShell Cmdlet: Part 4 of 9</title><link>http://blogs.technet.com/b/heyscriptingguy/archive/2012/10/02/build-your-own-powershell-cmdlet-part-4-of-9.aspx#3523792</link><pubDate>Tue, 02 Oct 2012 16:10:36 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:3523792</guid><dc:creator>Morimur36</dc:creator><description>&lt;p&gt;So I&amp;#39;m having an issue (probably user-related) but whenever I change the Parameter for the folder to an array I have a syntax issue on my file path. In other words, if I modify this line:&lt;/p&gt;
&lt;p&gt;[STRING]$Folder=&amp;quot;C:\PowerShell&amp;quot;,&lt;/p&gt;
&lt;p&gt;To become this line:&lt;/p&gt;
&lt;p&gt;[STRING[]]$Folder=&amp;quot;C:\PowerShell&amp;quot;,&lt;/p&gt;
&lt;p&gt;Whenever I call the function, it responds with this:&lt;/p&gt;
&lt;p&gt;_______________________________________________________________________________________________&lt;/p&gt;
&lt;p&gt;PS I:\&amp;gt; ADD-LOGFILE&lt;/p&gt;
&lt;p&gt;ADD-LOGFILE : Error: C:\PowerShell\ Logfile _ 10-2-2012 _ 120659 .log exist&lt;/p&gt;
&lt;p&gt;s.&lt;/p&gt;
&lt;p&gt;At line:1 char:12&lt;/p&gt;
&lt;p&gt;+ ADD-LOGFILE &amp;lt;&amp;lt;&amp;lt;&amp;lt; &lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;+ CategoryInfo &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;: WriteError: (:) [Write-Error], WriteErrorException&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;+ FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,ADD-LOGFILE&lt;/p&gt;
&lt;p&gt;C:\PowerShell&lt;/p&gt;
&lt;p&gt;\&lt;/p&gt;
&lt;p&gt;Logfile&lt;/p&gt;
&lt;p&gt;_&lt;/p&gt;
&lt;p&gt;10-2-2012&lt;/p&gt;
&lt;p&gt;_&lt;/p&gt;
&lt;p&gt;120659&lt;/p&gt;
&lt;p&gt;.log&lt;/p&gt;
&lt;p&gt;False&lt;/p&gt;
&lt;p&gt;_______________________________________________________________________________________________&lt;/p&gt;
&lt;p&gt;Any ideas on what I&amp;#39;ve managed to do wrong? It works as expected without that one change. To make sure I had things correct I also went back and copy/pasted.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.technet.com/aggbug.aspx?PostID=3523792" width="1" height="1"&gt;</description></item><item><title>re: Build Your Own PowerShell Cmdlet: Part 4 of 9</title><link>http://blogs.technet.com/b/heyscriptingguy/archive/2012/10/02/build-your-own-powershell-cmdlet-part-4-of-9.aspx#3523770</link><pubDate>Tue, 02 Oct 2012 13:56:23 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:3523770</guid><dc:creator>K_Schulte</dc:creator><description>&lt;p&gt;@PoSHV: You could well add this line of code after the &amp;quot;param&amp;quot; statement. It could act as the complete body of the function.&lt;/p&gt;
&lt;p&gt;@Sean: Batchman is back!!!&lt;/p&gt;
&lt;p&gt;Hi my friend, Sean!&lt;/p&gt;
&lt;p&gt;Good to &amp;quot;see&amp;quot; you again!!!&lt;/p&gt;
&lt;p&gt;I read through the first part of your series of blog entries here and just wanted to say &amp;quot;Hi!&amp;quot; to you :-))&lt;/p&gt;
&lt;p&gt;Well ... not only ... I have to admit ...&lt;/p&gt;
&lt;p&gt;Your explanation of the &amp;quot;DefaultParameterSetName&amp;quot; is quite ... let&amp;#39;s say &amp;quot;hard to understand&amp;quot; ...&lt;/p&gt;
&lt;p&gt;You don&amp;#39;t need a DefaultParameterSetName here at all and there is no parameter daclaration like:&lt;/p&gt;
&lt;p&gt;param(&lt;/p&gt;
&lt;p&gt;[Parameter(ParameterSetName=&amp;quot;Folder&amp;quot;)]&lt;/p&gt;
&lt;p&gt;[STRING]$Folder=&amp;quot;C:\PowerShell&amp;quot;,&lt;/p&gt;
&lt;p&gt; &amp;nbsp; ...&lt;/p&gt;
&lt;p&gt;)&lt;/p&gt;
&lt;p&gt;So there is no real effect of introducing a &amp;quot;DefaultParamterSet&amp;quot; here. &lt;/p&gt;
&lt;p&gt;But it might be too difficult to explain the reason of introducing this default.&lt;/p&gt;
&lt;p&gt;Anyway an example might help:&lt;/p&gt;
&lt;p&gt;If I got i right, this statement has been added to PS V2.0 in order to be able to allow for a &amp;quot;most appropriate behaviour&amp;quot; in case of ambiguous unnamed parameters!&lt;/p&gt;
&lt;p&gt;If we have:&lt;/p&gt;
&lt;p&gt;function f {&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;# [CmdletBinding(DefaultParametersetName=&amp;quot;Set2&amp;quot;)]&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;param( &lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;[Parameter(ParameterSetName=&amp;quot;Set1&amp;quot;,Position=0)] [string] $s,&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;[Parameter(ParameterSetName=&amp;quot;Set2&amp;quot;,Position=0)] [string] $i &lt;/p&gt;
&lt;p&gt; &amp;nbsp; ) &lt;/p&gt;
&lt;p&gt; &amp;nbsp; $PsCmdlet.ParameterSetName&lt;/p&gt;
&lt;p&gt;}&lt;/p&gt;
&lt;p&gt;the call: &lt;/p&gt;
&lt;p&gt;f 1&lt;/p&gt;
&lt;p&gt;will result in an error, because PS does&amp;#39;t know if we want $s or $i to be set unless we use named parameters!&lt;/p&gt;
&lt;p&gt;The way out is to specify a default solution to this conflict:&lt;/p&gt;
&lt;p&gt;And if we uncomment the second line, it works because of the DefaultParameterSet&lt;/p&gt;
&lt;p&gt;Way cool ...&lt;/p&gt;
&lt;p&gt;Klaus.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.technet.com/aggbug.aspx?PostID=3523770" width="1" height="1"&gt;</description></item><item><title>re: Build Your Own PowerShell Cmdlet: Part 4 of 9</title><link>http://blogs.technet.com/b/heyscriptingguy/archive/2012/10/02/build-your-own-powershell-cmdlet-part-4-of-9.aspx#3523753</link><pubDate>Tue, 02 Oct 2012 12:50:48 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:3523753</guid><dc:creator>PoSHV</dc:creator><description>&lt;p&gt;Where exactly in the script &amp;quot;If ($PSCmdlet.ShouldProcess(&amp;quot;Creation of Logfile $Logfilename Successful&amp;quot;)) { NEW-ITEM –Type File -path $Logfilename -Force | OUT-NULL } &amp;quot; should be added?&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.technet.com/aggbug.aspx?PostID=3523753" width="1" height="1"&gt;</description></item></channel></rss>