&lt;?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/"><channel><title>Articles from January 2012 on PowerShell.org - Welcome Automaters!</title><link>https://powershell.org/articles/2012/01/</link><description>Recent content in Articles from January 2012 on PowerShell.org - Welcome Automaters!</description><generator>Hugo</generator><language>en-us</language><atom:link href="https://powershell.org/articles/2012/01/index.xml" rel="self" type="application/rss+xml"/><item><title>PowerSE 2.7 KB: PowerShell profile does not load on startup</title><link>https://powershell.org/articles/2012-01-25-powerse-2-7-kb-powershell-profile-does-not-load-on-startup/</link><guid>https://powershell.org/articles/2012-01-25-powerse-2-7-kb-powershell-profile-does-not-load-on-startup/</guid><pubDate>Wed, 25 Jan 2012 19:01:59 +0000</pubDate><description>&lt;p&gt;Note: This blog post refers to an issue identified in PowerSE 2.7.0. It has been corrected in PowerSE 2.7.1, which is now available.&lt;/p&gt;
&lt;p&gt;With the release we published yesterday, both &lt;a href="http://powerwf.com/products/powerse.aspx"&gt;PowerSE&lt;/a&gt; and &lt;a href="http://powerwf.com/products/powerwf.aspx"&gt;PowerWF&lt;/a&gt; received a new feature: product-specific profiles.  This feature allows you to have profile scripts that you only want run in PowerSE or PowerWF run there so that you don&amp;quot;™t have to use if statements to check the host name in your profile scripts.  With this feature we also created the initial PowerSE and PowerWF profile scripts such that they dot-source the native PowerShell profile script by default so that what runs in PowerShell also runs in PowerSE.&lt;/p&gt;</description><content:encoded>&lt;![CDATA[<p>Note: This blog post refers to an issue identified in PowerSE 2.7.0. It has been corrected in PowerSE 2.7.1, which is now available.</p><p>With the release we published yesterday, both<a href="http://powerwf.com/products/powerse.aspx">PowerSE</a> and<a href="http://powerwf.com/products/powerwf.aspx">PowerWF</a> received a new feature: product-specific profiles.  This feature allows you to have profile scripts that you only want run in PowerSE or PowerWF run there so that you don"™t have to use if statements to check the host name in your profile scripts.  With this feature we also created the initial PowerSE and PowerWF profile scripts such that they dot-source the native PowerShell profile script by default so that what runs in PowerShell also runs in PowerSE.</p><p>Unfortunately there is one small detail that was left out of the PowerSE installer for this feature: the installation of the initial PowerSE-specific profile. As a result, if you download PowerSE 2.7, your PowerShell profile won"™t run right away.  Fortunately the fix is simple.  All you need to do is invoke this script from inside PowerSE 2.7:</p><blockquote><p>if (-not (Test-Path -LiteralPath $profile)) {<br>
    Set-Content -Path $profile -Value @&rsquo;<br>
if (Test-Path -LiteralPath $profile.CurrentUserPowerShellHost) {<br>
    . $profile.CurrentUserPowerShellHost<br>
}<br>
&lsquo;@<br>
}</p></blockquote><p>Once you have run that script, your PowerSE profile will exist and it will be defined to load your PowerShell profile.  Restart PowerSE 2.7 and you"™ll have your PowerShell profile loaded by default again.</p><p>Note that this does not apply to PowerWF users, the profile scripts were added correctly to the installer for that release.</p><p>My apologies for the inconvenience.  We hope to have this resolved in the product itself very soon.  In the meantime this short script should work around the issue for you.</p><p>Kirk out.</p><p>Technorati Tags:<a href="http://technorati.com/tags/PowerShell">PowerShell</a>,<a href="http://technorati.com/tags/PoSh">PoSh</a>,<a href="http://technorati.com/tags/Poshoholic">Poshoholic</a>,<a href="http://technorati.com/tags/PowerSE">PowerSE</a>,<a href="http://technorati.com/tags/KB">KB</a>,<a href="http://technorati.com/tags/profile">profile</a></p><p><a href="http://feeds.wordpress.com/1.0/gocomments/kirkmunro.wordpress.com/750/"><img src="http://feeds.wordpress.com/1.0/comments/kirkmunro.wordpress.com/750/" alt=""/><img src="http://stats.wordpress.com/b.gif?host=poshoholic.com&amp;blog=1436967&amp;%23038;post=750&amp;%23038;subd=kirkmunro&amp;%23038;ref=&amp;%23038;feed=1" alt=""/>
]]></content:encoded></item><item><title>PowerWF and PowerSE 2.7 are now available</title><link>https://powershell.org/articles/2012-01-24-powerwf-and-powerse-2-7-are-now-available/</link><guid>https://powershell.org/articles/2012-01-24-powerwf-and-powerse-2-7-are-now-available/</guid><pubDate>Tue, 24 Jan 2012 17:44:30 +0000</pubDate><description>&lt;p&gt;This morning &lt;a href="http://powerwf.com/products/powerwf.aspx"&gt;PowerWF&lt;/a&gt; and &lt;a href="http://powerwf.com/products/powerse.aspx"&gt;PowerSE&lt;/a&gt; 2.7 were released to the web and they can now be downloaded from &lt;a href="http://www.powerwf.com/"&gt;http://www.powerwf.com&lt;/a&gt;.  These releases offer a lot of new value to PowerWF and PowerSE users, as follows:&lt;/p&gt;
&lt;h4 id="powerwf-27-highlights" class="ps-heading"&gt;PowerWF 2.7 Highlights&lt;a class="ps-heading-anchor" href="#powerwf-27-highlights" aria-label="Link to this section" title="Link to this section"&gt;&lt;i class="fas fa-link" aria-hidden="true"&gt;&lt;/i&gt;&lt;/a&gt;
&lt;/h4&gt;
&lt;p&gt;&lt;strong&gt;New Start Page with New Workflows&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;The start page in PowerWF has been completely redesigned to provide immediate value out of the box for PowerWF customers.  The new design highlights the Workflow Library that is included with PowerWF, allowing customers to play workflows in the library without opening a workflow or script document.  Users can also customize the workflows on the start page and add their own groups of workflows for easier runbook automation.  This immediate out of the box value is included for PowerWF customers to allow them to leverage the power of Workflows and PowerShell in their environments without requiring any knowledge of PowerShell or Workflows.&lt;/p&gt;</description><content:encoded>&lt;![CDATA[<p>This morning<a href="http://powerwf.com/products/powerwf.aspx">PowerWF</a> and<a href="http://powerwf.com/products/powerse.aspx">PowerSE</a> 2.7 were released to the web and they can now be downloaded from<a href="http://www.powerwf.com/">http://www.powerwf.com</a>.  These releases offer a lot of new value to PowerWF and PowerSE users, as follows:</p><h4 id="powerwf-27-highlights" class="ps-heading">PowerWF 2.7 Highlights<a class="ps-heading-anchor" href="#powerwf-27-highlights" aria-label="Link to this section" title="Link to this section"><i class="fas fa-link" aria-hidden="true"/></a></h4><p><strong>New Start Page with New Workflows</strong></p><p>The start page in PowerWF has been completely redesigned to provide immediate value out of the box for PowerWF customers.  The new design highlights the Workflow Library that is included with PowerWF, allowing customers to play workflows in the library without opening a workflow or script document.  Users can also customize the workflows on the start page and add their own groups of workflows for easier runbook automation.  This immediate out of the box value is included for PowerWF customers to allow them to leverage the power of Workflows and PowerShell in their environments without requiring any knowledge of PowerShell or Workflows.</p><p><strong>New Management Packs for System Center Service Manager (SCSM)</strong></p><p>PowerWF for Service Manager has always included several useful management packs for SCSM in the product.  In this release, even more management packs for SCSM have been added.  Now, with a click of a button you can deploy management packs that automatically close resolved incidents, expire inactive problem announcements, cancel pending activities for closed change requests, identify problems from incident trends, notify incident authors about unresolved incidents, and get SCSM statistics.  These management packs are only available for licensed users of PowerWF for Service Manager.</p><p><strong>Improved Toolbox Search</strong></p><p>The search engine in the Activity toolbox just got better!  Now you can search using command names or keywords and PowerWF will return the best matches based on the terms you provided.  This includes searching with keywords that are only referenced in activity documentation and not in the command name itself.  For example, if you"™re a VMware administrator, simply entering &ldquo;vMotion&rdquo; into the search box will reveal the MoveVM activity that is necessary to perform vMotion tasks.</p><p><strong>Product-Specific Profile Support</strong></p><p>PowerWF now uses its own product-specific profile support, and it updates the $profile variable to include the paths to each of the relevant profiles that you use. By default the PowerWF profile dot-sources the native PowerShell console profile, however you can change this behaviour as required by simply modifying the profile yourself in PowerSE.</p><h4 id="powerse-27-highlights" class="ps-heading">PowerSE 2.7 Highlights<a class="ps-heading-anchor" href="#powerse-27-highlights" aria-label="Link to this section" title="Link to this section"><i class="fas fa-link" aria-hidden="true"/></a></h4><p><strong>Easier Breakpoint Management</strong></p><p>Breakpoint management in PowerSE just got a lot easier.  PowerSE now includes a Breakpoints pane to allow you to see all breakpoints you have set in your scripting environment, and you can now manage breakpoints using the breakpoint cmdlets and see the breakpoints you have created in the Breakpoints pane.  This gives you easy creation of line breakpoints using the Toggle Breakpoint feature or command and variable breakpoints using the Set-PSBreakpoint cmdlet (or sbp alias for short).</p><p><strong>Breakpoints Preserved Across Sessions</strong></p><p>Breakpoints are now automatically preserved across sessions, allowing you to continue debugging your scripts from one session to the next.  They are also preserved when you close a file, so you won"™t have to reset breakpoints each time you return to a script you were working on.  You can still remove breakpoints of course, using the Toggle Breakpoint feature or the Remove-PSBreakpoint cmdlet.</p><p><strong>Improved Help Search</strong></p><p>PowerShell help topic files are now included in the help search pane, allowing you to search for help for integral keywords like if or foreach, or for topics like &ldquo;Advanced functions&rdquo;, or you can learn more about remoting by searching for &ldquo;Remote&rdquo;.  Also, if no results are found when you search, PowerSE will now include a keyword search in command descriptions to allow for users to discover commands using related terms, such as &ldquo;vMotion&rdquo;.</p><p><strong>Product-Specific Profile Support</strong></p><p>PowerSE now uses its own product-specific profile support, and it updates the $profile variable to include the paths to each of the relevant profiles that you use.  By default the PowerSE profile dot-sources the native PowerShell console profile, however you can change this behaviour as required by simply modifying the profile yourself in PowerSE.</p><h4 id="and-thats-not-all" class="ps-heading">And that"™s not all!<a class="ps-heading-anchor" href="#and-thats-not-all" aria-label="Link to this section" title="Link to this section"><i class="fas fa-link" aria-hidden="true"/></a></h4><p>This shows you a few of the highlights of this release, but of course there were plenty of bug fixes, some performance improvements, and a few other minor enhancements that were included as well.  Whether you"™re a current PowerWF or PowerSE customer, or someone who is looking for great tools for working with PowerShell, Workflow, and Management Packs, I strongly encourage you to give this release a try and let us know what you think.</p><p>Kirk out.</p><p>Technorati Tags:<a href="http://technorati.com/tags/PowerShell">PowerShell</a>,<a href="http://technorati.com/tags/PoSh">PoSh</a>,<a href="http://technorati.com/tags/Poshoholic">Poshoholic</a>,<a href="http://technorati.com/tags/PowerWF">PowerWF</a>,<a href="http://technorati.com/tags/PowerSE">PowerSE</a>,<a href="http://technorati.com/tags/SCSM">SCSM</a>,<a href="http://technorati.com/tags/management+pack">management pack</a>,<a href="http://technorati.com/tags/workflow">workflow</a></p><p><a href="http://feeds.wordpress.com/1.0/gocomments/kirkmunro.wordpress.com/747/"><img src="http://feeds.wordpress.com/1.0/comments/kirkmunro.wordpress.com/747/" alt=""/><img src="http://stats.wordpress.com/b.gif?host=poshoholic.com&amp;blog=1436967&amp;%23038;post=747&amp;%23038;subd=kirkmunro&amp;%23038;ref=&amp;%23038;feed=1" alt=""/>
]]></content:encoded></item><item><title>Essential PowerShell: To alias, or not to alias, that is the question</title><link>https://powershell.org/articles/2012-01-05-essential-powershell-to-alias-or-not-to-alias-that-is-the-question/</link><guid>https://powershell.org/articles/2012-01-05-essential-powershell-to-alias-or-not-to-alias-that-is-the-question/</guid><pubDate>Thu, 05 Jan 2012 14:30:00 +0000</pubDate><description>&lt;p&gt;Recently there was a discussion between community experts and a product team about a module they are working on.  The topic being discussed was cmdlet aliases: whether or not they should provide aliases for their cmdlets out of the box and if so, how they should be provided.  Aliases are great for ad-hoc PowerShell work, which is what most PowerShell users do at this point, and incredibly useful when you&amp;quot;™re trying to put out a fire and managing your infrastructure using PowerShell.  However, there are many important things that module authors need to consider when planning aliases for their cmdlets, as follows:&lt;/p&gt;</description><content:encoded>&lt;![CDATA[<p>Recently there was a discussion between community experts and a product team about a module they are working on.  The topic being discussed was cmdlet aliases: whether or not they should provide aliases for their cmdlets out of the box and if so, how they should be provided.  Aliases are great for ad-hoc PowerShell work, which is what most PowerShell users do at this point, and incredibly useful when you"™re trying to put out a fire and managing your infrastructure using PowerShell.  However, there are many important things that module authors need to consider when planning aliases for their cmdlets, as follows:</p><ol><li><p>There are many cmdlets out now, and more and more every month.  Coming up with a vsa (very short alias) that is<em>unique</em> is a challenge at best, and the more time goes by the more tla&rsquo;s (three-letter aliases) will get used up.  The likelihood of an alias conflict is already high, and increasing all the time given the number of commands that are available both from Microsoft and from third party vendors.</p></li><li><p>The land grab with alias names is worse than it is with functions or cmdlets.  With functions or cmdlets, you can have multiple modules loaded with conflicting names and access either command using the fully qualified command name.  With aliases though you are not provided this same capability &ldquo;“ there can be only one.  Aliases are simply commands set to a single value and they cannot be qualified using a module name qualifier to disambiguate if a name conflict arises.</p></li><li><p>Depending on how careful (or not) that developers are, it is very easy for a module author to completely take over (overwrite) an existing alias with no warning or message indicating that this has happened, resulting in potential command hijacking between module teams.  A simple call to Set-Alias does this without warning.  On the flipside, if developers don&rdquo;™t hijack aliases, then some of the aliases they would otherwise create may simply not be defined.</p></li><li><p>When aliases are hijacked, unloading a module doesn&rsquo;t correct the problem because an alias that was overwritten by a module alias will simply become completely unavailable when the alias is removed as the module is unloaded.</p></li></ol><p>As far as I am aware, this situation does not improve with the next version of PowerShell either, so it&rsquo;s years away from getting better.</p><p>Believe it or not, even with these things in mind, I&rsquo;m actually still pro aliases.  I just think that some extra care/thought needs to be put into their definition.  There is no real standard here that both satisfactorily addresses the issues identified above and that allows for consistency across companies/teams at this time.  Given that is the current state of affairs, if you are considering aliases for your module I recommend one of the following approaches:</p><ol><li><p>[SAFEST] Rather than trying to come up with something that can be shipped despite these issues, at this time I think aliases would be best addressed in a &ldquo;tips and tricks&rdquo; type of blog post, proposing a short script that defines some useful aliases for the module/snapin in question in order to allow admins to be able to deal with fires quickly using ad-hoc PowerShell commands via some aliases.  Such a script should generate warnings whenever a name conflict is discovered so that users are aware when an alias either cannot be created or is overwritten.</p></li><li><p>[EXPERIMENTAL] Ship aliases with your module, but try to make sure they really are unique.  For example, if you"™re a vendor whose company name starts with Q, you could prefix all of your aliases with &ldquo;q&rdquo;.  This is attractive because there are no verbs that start with &ldquo;q&rdquo;, so right from the start you&rsquo;ve dramatically reduced the chance that you&rsquo;ll have a conflict, setting yourselves up better to have aliases that belong to you.  Then you would only have to coordinate within your company to make sure the aliases used across teams are unique.  This isn"™t foolproof though because there may be multiple products/vendors that adopt the same standard, and if the name of your company or product starts with G, the likelihood of a conflict would be much higher (the alias prefix used for &ldquo;get-*&rdquo; cmdlets is &ldquo;g&rdquo;) so you may want to choose a pair of letters instead.  Regardless, you&rsquo;ve likely reduced the risk, and you could generate a warning whenever you run into a conflict that prevents an alias from being created.</p></li><li><p>[RECOMMENDED] Lots of 1 and a little bit of 2: use unique alias names that work for your product team/company, but don&rsquo;t ship them with the module.  Instead, push them out as a value add on a blog post, and see how the community responds.  At the same time work with MVPs and Microsoft to get these issues addressed such that a shorthand system for command names does work.  Some MVPs, already proposed a few things to the Microsoft PowerShell team that could help here (aliases for module names for one — think PS\gsv for a core PowerShell version of Get-Service or EX\gu for the Get-User cmdlet that comes with the Microsoft Exchange module or AD\gu for the Get-User cmdlet that comes with the Microsoft Active Directory module, and so on), but more discussions need to happen and this will take more time.</p></li></ol><p>I recommend the third option because given the current issues with alias hijacking and with no support for disambiguation, it seems to be the best solution for now (from my perspective at least).  If you have come up with other alternatives that resolve these issues, please share them with the community so that this improves going forward.</p><p>Hope this helps,</p><p>Kirk out.</p><p>Technorati Tags:<a href="http://technorati.com/tags/PowerShell">PowerShell</a>,<a href="http://technorati.com/tags/PoSh">PoSh</a>,<a href="http://technorati.com/tags/Poshoholic">Poshoholic</a>,<a href="http://technorati.com/tags/Essential+PowerShell">Essential PowerShell</a>,<a href="http://technorati.com/tags/alias">alias</a></p><p><a href="http://feeds.wordpress.com/1.0/gocomments/kirkmunro.wordpress.com/738/"><img src="http://feeds.wordpress.com/1.0/comments/kirkmunro.wordpress.com/738/" alt=""/><img src="http://stats.wordpress.com/b.gif?host=poshoholic.com&amp;blog=1436967&amp;%23038;post=738&amp;%23038;subd=kirkmunro&amp;%23038;ref=&amp;%23038;feed=1" alt=""/>
]]></content:encoded></item><item><title>PowerShell MVP for 2012</title><link>https://powershell.org/articles/2012-01-04-powershell-mvp-for-2012/</link><guid>https://powershell.org/articles/2012-01-04-powershell-mvp-for-2012/</guid><pubDate>Wed, 04 Jan 2012 17:51:39 +0000</pubDate><description>&lt;p&gt;Every year around Christmas I anxiously await the New Year to see if I receive the Microsoft MVP award again that year.  Well that email came on January 1, 2012, and I&amp;quot;™m quite thrilled about this one because it&amp;quot;™s a milestone this time (year 5 as a PowerShell MVP).  Thanks to the community for being so great to work with, and thanks to Microsoft both for recognizing individual efforts with the MVP program and for creating such great products like Windows PowerShell!  Work has never been so much fun!&lt;/p&gt;</description><content:encoded>&lt;![CDATA[<p>Every year around Christmas I anxiously await the New Year to see if I receive the Microsoft MVP award again that year.  Well that email came on January 1, 2012, and I"™m quite thrilled about this one because it"™s a milestone this time (year 5 as a PowerShell MVP).  Thanks to the community for being so great to work with, and thanks to Microsoft both for recognizing individual efforts with the MVP program and for creating such great products like Windows PowerShell!  Work has never been so much fun!</p><p>Kirk out.</p><p>Technorati Tags:<a href="http://technorati.com/tags/PowerShell">PowerShell</a>,<a href="http://technorati.com/tags/PoSh">PoSh</a>,<a href="http://technorati.com/tags/Poshoholic">Poshoholic</a>,<a href="http://technorati.com/tags/Microsoft+MVP">Microsoft MVP</a></p><p><a href="http://feeds.wordpress.com/1.0/gocomments/kirkmunro.wordpress.com/740/"><img src="http://feeds.wordpress.com/1.0/comments/kirkmunro.wordpress.com/740/" alt=""/><img src="http://stats.wordpress.com/b.gif?host=poshoholic.com&amp;blog=1436967&amp;%23038;post=740&amp;%23038;subd=kirkmunro&amp;%23038;ref=&amp;%23038;feed=1" alt=""/>
]]></content:encoded></item><item><title>PowerShell V3 CTP2 Provides Better Argument Passing to EXEs</title><link>https://powershell.org/articles/2012-01-02-powershell-v3-ctp2-provides-better-argument-passing-to-exes/</link><guid>https://powershell.org/articles/2012-01-02-powershell-v3-ctp2-provides-better-argument-passing-to-exes/</guid><pubDate>Mon, 02 Jan 2012 19:56:23 +0000</pubDate><description>&lt;p&gt;Within PowerShell it has always been easy to pass &amp;ldquo;simple&amp;rdquo; arguments to an EXE e.g.:&lt;/p&gt;
&lt;p&gt;&lt;code&gt;C:\PS&amp;gt; ipconfig -all &lt;/code&gt;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&amp;quot;™s special characters e.g.:&lt;/p&gt;</description><content:encoded>&lt;![CDATA[<p>Within PowerShell it has always been easy to pass &ldquo;simple&rdquo; arguments to an EXE e.g.:</p><p><code>C:\PS&gt; ipconfig -all</code>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><p>`C:\PS&gt; tf.exe status . /workspace:HILLR1;hillr /r
There are no pending changes.
The term &lsquo;hillr&rsquo; 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</p><ul><li>tf.exe status . /workspace:HILLR1;hillr /r</li><li><pre><code> ~~~~~</code></pre><ul><li>CategoryInfo : ObjectNotFound: (hillr:String) [], CommandNotFoundException</li><li>FullyQualifiedErrorId : CommandNotFoundException
`Note that in the command line above the &ldquo;/workspace&rdquo; parameter value is specified using a special syntax that TF.exe recognizes i.e. ;.  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:</li></ul></li></ul><p><code>C:\PS&gt; echoargs.exe status . /workspace:HILLR1;hillr /r Arg 0 is Arg 1 is &lt;.&gt; Arg 2 is</code>In this case, the solution is simple &ldquo;“ just escape the semicolon e.g.:</p><p><code>C:\PS&gt; tf.exe status . /r /workspace:HILLR1</code>;hillr
File name Change Local path</p><hr><p>$/Foo/Trunk/Tools/Bin
TfsTools.psm1 edit C:\Tfs\Foo\Trunk\Tools\Bin\TfsTools.psm1
1 change(s)
`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 &ldquo;as-is&rdquo;.  In other words, you can tell PowerShell to become a &ldquo;dumber&rdquo; command line parser.  This mode is invoked using the character sequence: &ldquo;“% 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&rdquo;™s how you use it.  Take this example of a problematic set of command line parameters:</p><p>`C:\PS&gt; sqlcmd -S .\SQLEXPRESS -v lname=&ldquo;Gates&rdquo; -Q &ldquo;SELECT FirstName,LastName FROM
AdventureWorks.Person.Contact WHERE LastName = &lsquo;$(lname)&rsquo;&rdquo;
The term &rsquo;lname&rsquo; 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</p><ul><li>&hellip; LastName = &lsquo;$(lname)&rsquo;&rdquo;</li><li><pre><code> ~~~~~</code></pre><ul><li>CategoryInfo : ObjectNotFound: (lname:String) [], CommandNotFou
ndException</li><li>FullyQualifiedErrorId : CommandNotFoundException<code>In this case the V2 solution is to escape the $ character in the last part of the command line e.g.: '</code>$(lname)&rsquo; but if you don"™t want to spend the time to figure this out you can easily use –% like so:</li></ul></li></ul><p>`C:\PS&gt; sqlcmd &ndash;% -S .\SQLEXPRESS -v lname=&ldquo;Gates&rdquo; -Q &ldquo;SELECT FirstName,LastName F
ROM AdventureWorks.Person.Contact WHERE LastName = &lsquo;$(lname)&rsquo;&rdquo;
FirstName LastName</p><hr><p>Janet Gates
(1 rows affected)
`You can put the –% 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 –% the rest of the command line will be parsed &ldquo;dumbly&rdquo;.  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><p>`C:\PS&gt; $env:colname = &ldquo;LastName&rdquo;
C:\PS&gt; sqlcmd -S .\SQLEXPRESS -v lname=&ldquo;Gates&rdquo; &ndash;% -Q &ldquo;SELECT FirstName,LastName F
ROM AdventureWorks.Person.Contact WHERE %colname% = &lsquo;$(lname)&rsquo;&rdquo;
FirstName LastName</p><hr><p>Janet Gates
(1 rows affected)
`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><p><a href="http://feeds.wordpress.com/1.0/gocomments/rkeithhill.wordpress.com/241/"><img src="http://feeds.wordpress.com/1.0/comments/rkeithhill.wordpress.com/241/" alt=""/><img src="http://stats.wordpress.com/b.gif?host=rkeithhill.wordpress.com&amp;blog=18780344&amp;%23038;post=241&amp;%23038;subd=rkeithhill&amp;%23038;ref=&amp;%23038;feed=1" alt=""/>
]]></content:encoded></item></channel></rss>