<?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>PowerShell Ponderings &#187; Powershell &#8211; Cmdlets</title>
	<atom:link href="http://andrwwatt.wordpress.com/category/powershell-cmdlets/feed/" rel="self" type="application/rss+xml" />
	<link>http://andrwwatt.wordpress.com</link>
	<description>Pondering the power of PowerShell</description>
	<lastBuildDate>Fri, 19 May 2006 09:06:24 +0000</lastBuildDate>
	<generator>http://wordpress.com/</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<cloud domain='andrwwatt.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://www.gravatar.com/blavatar/7a3577429727eb864e230a6da306b64a?s=96&#038;d=http://s.wordpress.com/i/buttonw-com.png</url>
		<title>PowerShell Ponderings &#187; Powershell &#8211; Cmdlets</title>
		<link>http://andrwwatt.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://andrwwatt.wordpress.com/osd.xml" title="PowerShell Ponderings" />
		<item>
		<title>Coping with a PowerShell naming clash</title>
		<link>http://andrwwatt.wordpress.com/2006/05/13/coping-with-a-powershell-naming-clash/</link>
		<comments>http://andrwwatt.wordpress.com/2006/05/13/coping-with-a-powershell-naming-clash/#comments</comments>
		<pubDate>Sat, 13 May 2006 16:32:56 +0000</pubDate>
		<dc:creator>andrwwatt</dc:creator>
				<category><![CDATA[PowerShell - Aliases]]></category>
		<category><![CDATA[PowerShell - Functions]]></category>
		<category><![CDATA[Powershell - Cmdlets]]></category>

		<guid isPermaLink="false">https://andrwwatt.wordpress.com/2006/05/13/coping-with-a-powershell-naming-clash/</guid>
		<description><![CDATA[Naming clashes are something I expect to increase in frequency when PowerShell starts to be used more widely. I thought I would show you how to solve some categories of naming clashes. I will deal here with some of the situations that can arise when naming functions using names similar to cmdlets, that is verb-noun.
The [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=andrwwatt.wordpress.com&blog=221566&post=8&subd=andrwwatt&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>Naming clashes are something I expect to increase in frequency when PowerShell starts to be used more widely. I thought I would show you how to solve some categories of naming clashes. I will deal here with some of the situations that can arise when naming functions using names similar to cmdlets, that is <i>verb-noun</i>.</p>
<p>The situation can, potentially, become really complex so I will deal in this post only with some simple situations.</p>
<p>The name of a function can clash with an existing alias or cmdlet name. As an example consider what happens if you have written a function called <b>rename-item</b>.  If you&#39;ve been reading recent posts on this blog you will know that PowerShell has a <b>rename-item</b> cmdlet.</p>
<p>Assume that you have opened a fresh PowerShell console window.</p>
<p>If you type <b>rename-item</b> at the command line then you see a prompt</p>
<p><b>PS C:\&gt; rename-item</b></p>
<p><b>cmdlet rename-item at command pipeline position 1<br />
Supply values for the following parameters:<br />
Path: </b></p>
<p>PowerShell prompts you to supply a value for the <b>Path</b> parameter.</p>
<p>Press Ctrl+C to stop this.</p>
<p>At the command line type the following to create the <b>rename-item</b> function:</p>
<p><b>function rename-item{</b></p>
<p><b>write-host &quot;This output is from the rename-item function&quot;</b></p>
<p><b>} </b></p>
<p>Then type at the command line:</p>
<p><b>rename-item</b></p>
<p>You will see an appearance like this:</p>
<p><b>PS C:\&gt; rename-item<br />
This output is from the rename-item function<br />
PS C:\&gt; </b></p>
<p>By creating a function called <b>rename-item</b> you have, effectively, blocked execution of the <b>rename-item</b> cmdlet at the command line.</p>
<p>Why does this happen? PowerShell attempts to find an executable to match a command in the following order:</p>
<ol>
<li>Aliases</li>
<li>Functions</li>
<li>Cmdlets</li>
<li>Executables</li>
<li>Scripts</li>
<li>Normal files</li>
</ol>
<p>So when you created the <b>rename-item</b> function it takes precedence over the <b>rename-item</b> cmdlet.</p>
<p>If you want to be sure to have access to the <b>rename-item</b> cmdlet avoid creating a global function with that name since the function will always have higher priority than the cmdlet.</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/andrwwatt.wordpress.com/8/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/andrwwatt.wordpress.com/8/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/andrwwatt.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/andrwwatt.wordpress.com/8/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/andrwwatt.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/andrwwatt.wordpress.com/8/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/andrwwatt.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/andrwwatt.wordpress.com/8/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/andrwwatt.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/andrwwatt.wordpress.com/8/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/andrwwatt.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/andrwwatt.wordpress.com/8/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=andrwwatt.wordpress.com&blog=221566&post=8&subd=andrwwatt&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://andrwwatt.wordpress.com/2006/05/13/coping-with-a-powershell-naming-clash/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/bbd01d97e4b6b8a5c05a55b10c599ce2?s=96&#38;d=identicon" medium="image">
			<media:title type="html">andrwwatt</media:title>
		</media:content>
	</item>
		<item>
		<title>Limitations of the rename-item cmdlet</title>
		<link>http://andrwwatt.wordpress.com/2006/05/13/limitations-of-the-rename-item-cmdlet/</link>
		<comments>http://andrwwatt.wordpress.com/2006/05/13/limitations-of-the-rename-item-cmdlet/#comments</comments>
		<pubDate>Sat, 13 May 2006 12:47:12 +0000</pubDate>
		<dc:creator>andrwwatt</dc:creator>
				<category><![CDATA[PowerShell - Scripts]]></category>
		<category><![CDATA[Powershell - Cmdlets]]></category>

		<guid isPermaLink="false">https://andrwwatt.wordpress.com/2006/05/13/limitations-of-the-rename-item-cmdlet/</guid>
		<description><![CDATA[If you&#39;ve been using Monad betas before the release of PowerShell RC1 you quite possibly have a significant number of scripts that you wrote using the Monad betas. Those files will have a .msh file extension. When you upgrade to PowerShell, apart from any changes you need to make to the content, you need to [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=andrwwatt.wordpress.com&blog=221566&post=7&subd=andrwwatt&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>If you&#39;ve been using Monad betas before the release of PowerShell RC1 you quite possibly have a significant number of scripts that you wrote using the Monad betas. Those files will have a <b>.msh</b> file extension. When you upgrade to PowerShell, apart from any changes you need to make to the content, you need to change the file extension to <b>.ps1</b>.</p>
<p>In the good old Windows command shell, doing that is straightforward. Simply navigate to the folder holding the scripts. Then use the following command:</p>
<p><b>ren *.msh *.ps1</b></p>
<p>If you try that with Monad you receive the following error:</p>
<p><b>PS C:\PowerShellScripts&gt; ren *.msh *.ps1<br />
Rename-Item : Cannot process argument because the value of argument &quot;path&quot; is invalid. At line:1 char:4<br />
+ ren  &lt;&lt;&lt;&lt; *.msh *.ps1</b></p>
<p>So, what&#39;s wrong with the path? To figure that out I will show the command in a full form:</p>
<p><b>ren -Path *.msh -NewName *.ps1</b></p>
<p>The error relates to the value of the <b>Path</b> parameter. It accepts wildcards in the path but it must resolve to a single file.</p>
<p>So how do you use PowerShell to rename multiple files?</p>
<p>PowerShell is designed to use pipelines. And you need a two step pipeline to get the job done. Assuming you are in the directory that contains the files that you want to rename, use the following command:</p>
<p><b>get-childitem -Path *.msh | </b></p>
<p><b>rename-item -NewName {$_.name -replace &quot;.msh&quot;,&quot;.ps1&quot;} -whatif</b></p>
<p>As you can see it&#39;s a pipeline with two steps. The first step uses the <b>get-childitem</b> cmdlet to retrieve information about all files in the current folder with a <b>.msh</b> file extension. The second step uses the <b>rename-item</b> cmdlet to process each object passed on from the first step. Each object is a <b>FileInfo</b> object. The value of the Extension property of each <b>FileInfo</b> object is <b>.msh</b>, as you can see by using the following command:</p>
<p><b>get-childitem *.msh |</b></p>
<p><b>format-table Name, Extension</b></p>
<p>The value of the <b>NewName</b> parameter is <b>{$_.name -replace &quot;.msh&quot;,&quot;.ps1&quot;}</b>. Any occurrence of <b>.msh</b> in the value of the <b>Name</b> property of the current object is replaced by <b>.ps1</b>.</p>
<p>To put it more succinctly, all files with a file extension of <b>.msh</b> are renamed to have a file extension of <b>.ps1</b>.</p>
<p>In Windows Explorer you can rename the current folder. The <b>rename-item</b> cmdlet doesn&#39;t allow you to rename any folder.</p>
<p>The example I showed used the <b>FileSystem</b> provider. You can use the <b>rename-item</b> cmdlet to rename items in other providers, for example the <b>alias</b> and <b>variable</b> providers. To display available providers use this command:</p>
<p><b>get-PSDrive</b></p>
<p>The <b>get-PSDrive</b> cmdlet has replaced the <b>get-drive</b> cmdlet which was found in public builds before RC1.</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/andrwwatt.wordpress.com/7/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/andrwwatt.wordpress.com/7/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/andrwwatt.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/andrwwatt.wordpress.com/7/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/andrwwatt.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/andrwwatt.wordpress.com/7/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/andrwwatt.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/andrwwatt.wordpress.com/7/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/andrwwatt.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/andrwwatt.wordpress.com/7/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/andrwwatt.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/andrwwatt.wordpress.com/7/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=andrwwatt.wordpress.com&blog=221566&post=7&subd=andrwwatt&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://andrwwatt.wordpress.com/2006/05/13/limitations-of-the-rename-item-cmdlet/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/bbd01d97e4b6b8a5c05a55b10c599ce2?s=96&#38;d=identicon" medium="image">
			<media:title type="html">andrwwatt</media:title>
		</media:content>
	</item>
	</channel>
</rss>