<?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>Huddled Masses &#187; Path</title>
	<atom:link href="http://huddledmasses.org/tag/path/feed/" rel="self" type="application/rss+xml" />
	<link>http://huddledmasses.org</link>
	<description>You can do more than breathe for free...</description>
	<lastBuildDate>Sat, 28 Jan 2012 21:37:20 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
<cloud domain='huddledmasses.org' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
		<item>
		<title>Long-Path Module (Experimental.IO)</title>
		<link>http://huddledmasses.org/long-path-module-experimental-io/</link>
		<comments>http://huddledmasses.org/long-path-module-experimental-io/#comments</comments>
		<pubDate>Fri, 04 Feb 2011 06:01:23 +0000</pubDate>
		<dc:creator>Joel 'Jaykul' Bennett</dc:creator>
				<category><![CDATA[Huddled]]></category>
		<category><![CDATA[.Net]]></category>
		<category><![CDATA[IO]]></category>
		<category><![CDATA[Path]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[Windows]]></category>

		<guid isPermaLink="false">http://huddledmasses.org/?p=1651</guid>
		<description><![CDATA[Thanks to a late night on my part, and the efforts of the developers on the Microsoft BCL project who wrote the Experimental.IO LongPath assembly &#8230; with no further ado, I present a really basic module for dealing with long file paths. There&#8217;s no help yet, and very little error handling. But if you needed [...]]]></description>
			<content:encoded><![CDATA[	<p>Thanks to a late night on my part, and the efforts of the developers on the <a href="http://bcl.codeplex.com/">Microsoft <span class="caps">BCL</span> project</a> who wrote the Experimental.IO <a href="http://bcl.codeplex.com/releases/view/42783">LongPath</a> assembly &#8230; with no further ado, I present a really basic module for dealing with long file paths. </p>

	<p>There&#8217;s no help yet, and very little error handling. But if you needed long paths (I know one of you did, because Jacques Willemen asked for it), then here are: Get-LongPath, Copy-LongPath, Move-LongPath, Remove-LongPath, Get-ContentLongPath, Set-ContentLongPath &#8230; and &#8230; uhm &#8230; Format-Color</p>

	<p><a href="http://HuddledMasses.org/downloads/Experimental.IO.zip">Download the Experimental.IO Long Path Module</a></p>

	<p>The script source is <a href="http://poshcode.org/2488">on PoshCode</a> so please help me: write the next version of this module by contributing there.</p>]]></content:encoded>
			<wfw:commentRss>http://huddledmasses.org/long-path-module-experimental-io/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PowerShell Power User Tips: A Better Prompt</title>
		<link>http://huddledmasses.org/powershell-power-user-tips-a-better-prompt/</link>
		<comments>http://huddledmasses.org/powershell-power-user-tips-a-better-prompt/#comments</comments>
		<pubDate>Wed, 13 Aug 2008 03:49:30 +0000</pubDate>
		<dc:creator>Joel 'Jaykul' Bennett</dc:creator>
				<category><![CDATA[Huddled]]></category>
		<category><![CDATA[CurrentDirectory]]></category>
		<category><![CDATA[Path]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[PowerTips]]></category>
		<category><![CDATA[Scripting]]></category>
		<category><![CDATA[Tips]]></category>

		<guid isPermaLink="false">http://HuddledMasses.org/?p=628</guid>
		<description><![CDATA[For this edition of my Power User tips for PowerShell, I&#8217;m going to share my (heavily annotated) prompt function. Feel free to to copy useful pieces or just place the whole thing in your profile script I&#8217;m not going to say anything more, I&#8217;ll let the comments speak for themselves. Edit: Someone just pointed out [...]]]></description>
			<content:encoded><![CDATA[	<p>For this edition of my Power User tips for PowerShell, I&#8217;m going to share my (heavily annotated) prompt function. Feel free to to copy useful pieces or just place the whole thing in your profile script  <img src='http://huddledmasses.org/wordpress/wp-includes/' alt=':)' class='wp-smiley' />   I&#8217;m not going to say anything more, I&#8217;ll let the comments speak for themselves.</p>

	<p><strong>Edit</strong>: Someone just pointed out that I forgot the bit of my prompt that sets my current path into the window title, and I realized I also forgot the bit that puts (Admin) in the title if you&#8217;re running &#8220;elevated&#8221; on Vista.</p>

	<p> <img src='http://huddledmasses.org/wordpress/wp-includes/' alt='[new]' class='wp-smiley' />  <strong>Edit</strong>: Ok, how many people noticed that I incorrectly used the Environement.CurrentDirectory when I set the WindowTitle (meaning it would only work right in FileSystem drives)?  Fixed now.</p>

	<div class="posh code posh" style="font-family:monospace;"><br />
<span style="color: #666666; font-style: italic;"># Set-Prompt.ps1 (Dot-Source from your profile)</span><br />
<span style="color: #666666; font-style: italic;">###################################################</span><br />
<span style="color: #666666; font-style: italic;"># This should go OUTSIDE the prompt function, it doesn't need re-evaluation</span><br />
<span style="color: #666666; font-style: italic;"># We're going to calculate a prefix for the window title </span><br />
<span style="color: #666666; font-style: italic;"># Our basic title is &quot;PoSh - C:\Your\Path\Here&quot; showing the current path</span><br />
<span style="color: #666699; font-weight: bold;">if</span><span style="color: #333;">&#40;</span><span style="color: #66cc66;">!</span><span style="color: #660033; font-weight: bold;">$global</span>:WindowTitlePrefix<span style="color: #333;">&#41;</span> <span style="color: #333;">&#123;</span><br />
&nbsp; &nbsp;<span style="color: #666666; font-style: italic;"># But if you're running &quot;elevated&quot; on vista, we want to show that ...</span><br />
&nbsp; &nbsp;<span style="color: #666699; font-weight: bold;">if</span><span style="color: #333;">&#40;</span> <span style="color: #333;">&#40;</span><span style="color: #003366; font-weight: bold;"><span style="color: #333;">&#91;</span>System.<span style="color: #003366;">Environment</span><span style="color: #333;">&#93;</span></span>::<span style="color: #003366;">OSVersion</span>.<span style="color: #003366;">Version</span>.<span style="color: #003366;">Major</span> <span style="color: #000066;">-gt</span> <span style="color: #cc66cc;">5</span><span style="color: #333;">&#41;</span> <span style="color: #000066;">-and</span> <span style="color: #333;">&#40;</span> <span style="color: #666666; font-style: italic;"># Vista and ...</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #0066cc; font-style: italic;">new-<span style="font-style: normal;">object</span></span> Security.<span style="color: #003366;">Principal</span>.<span style="color: #003366;">WindowsPrincipal</span> <span style="color: #333;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003366; font-weight: bold;"><span style="color: #333;">&#91;</span>Security.<span style="color: #003366;">Principal</span>.<span style="color: #003366;">WindowsIdentity</span><span style="color: #333;">&#93;</span></span>::<span style="color: #003366;">GetCurrent</span><span style="color: #333;">&#40;</span><span style="color: #333;">&#41;</span><span style="color: #333;">&#41;</span> <span style="color: #666666; font-style: italic;"># current user is admin</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #333;">&#41;</span>.<span style="color: #003366;">IsInRole</span><span style="color: #333;">&#40;</span><span style="color: #003366; font-weight: bold;"><span style="color: #333;">&#91;</span>Security.<span style="color: #003366;">Principal</span>.<span style="color: #003366;">WindowsBuiltInRole</span><span style="color: #333;">&#93;</span></span>::<span style="color: #003366;">Administrator</span><span style="color: #333;">&#41;</span> <span style="color: #333;">&#41;</span><br />
&nbsp; &nbsp;<span style="color: #333;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #660033; font-weight: bold;">$global</span>:WindowTitlePrefix <span style="color: #66cc66;">=</span> <span style="color: #009900;">&quot;PoSh (ADMIN)&quot;</span><br />
&nbsp; &nbsp;<span style="color: #333;">&#125;</span> <span style="color: #666699; font-weight: bold;">else</span> <span style="color: #333;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #660033; font-weight: bold;">$global</span>:WindowTitlePrefix <span style="color: #66cc66;">=</span> <span style="color: #009900;">&quot;PoSh&quot;</span><br />
&nbsp; &nbsp;<span style="color: #333;">&#125;</span><br />
<span style="color: #333;">&#125;</span><br />
<br />
<span style="color: #666699; font-weight: bold;">function</span> <span style="color: #660033;">prompt</span> <span style="color: #333;">&#123;</span><br />
&nbsp; &nbsp;<span style="color: #666666; font-style: italic;"># FIRST, make a note if there was an error in the previous command</span><br />
&nbsp; &nbsp;<span style="color: #660033; font-weight: bold;">$err</span> <span style="color: #66cc66;">=</span> <span style="color: #66cc66;">!</span>$?<br />
<br />
&nbsp; &nbsp;<span style="color: #666666; font-style: italic;"># Make sure Windows and .Net know where we are (they can only handle the FileSystem)</span><br />
&nbsp; &nbsp;<span style="color: #003366; font-weight: bold;"><span style="color: #333;">&#91;</span>Environment<span style="color: #333;">&#93;</span></span>::<span style="color: #003366;">CurrentDirectory</span> <span style="color: #66cc66;">=</span> <span style="color: #333;">&#40;</span><span style="color: #0066cc; font-style: italic;">Get-<span style="font-style: normal;">Location</span></span> <span style="color: #000066;">-PSProvider</span> FileSystem<span style="color: #333;">&#41;</span>.<span style="color: #003366;">ProviderPath</span><br />
&nbsp; &nbsp;<span style="color: #666666; font-style: italic;"># Also, put the path in the title ... (don't restrict this to the FileSystem</span><br />
&nbsp; &nbsp;<span style="color: #660033; font-weight: bold;">$Host</span>.<span style="color: #003366;">UI</span>.<span style="color: #003366;">RawUI</span>.<span style="color: #003366;">WindowTitle</span> <span style="color: #66cc66;">=</span> <span style="color: #009900;">&quot;{0} - {1} ({2})&quot;</span> <span style="color: #000066;">-f</span> <span style="color: #660033; font-weight: bold;">$global</span>:WindowTitlePrefix,<span style="color: #660033; font-weight: bold;">$pwd</span>.<span style="color: #003366;">Path</span>,<span style="color: #660033; font-weight: bold;">$pwd</span>.<span style="color: #003366;">Provider</span>.<span style="color: #003366;">Name</span><br />
&nbsp; &nbsp;<br />
&nbsp; &nbsp;<span style="color: #666666; font-style: italic;"># Determine what nesting level we are at (if any)</span><br />
&nbsp; &nbsp;<span style="color: #660033; font-weight: bold;">$Nesting</span> <span style="color: #66cc66;">=</span> <span style="color: #009900;">&quot;$([char]0xB7)&quot;</span> <span style="color: #66cc66;">*</span> <span style="color: #660033; font-weight: bold;">$NestedPromptLevel</span><br />
<br />
&nbsp; &nbsp;<span style="color: #666666; font-style: italic;"># Generate PUSHD(push-location) Stack level string</span><br />
&nbsp; &nbsp;<span style="color: #660033; font-weight: bold;">$Stack</span> <span style="color: #66cc66;">=</span> <span style="color: #009900;">&quot;+&quot;</span> <span style="color: #66cc66;">*</span> <span style="color: #333;">&#40;</span><span style="color: #0066cc; font-style: italic;">Get-<span style="font-style: normal;">Location</span></span> <span style="color: #000066;">-Stack</span><span style="color: #333;">&#41;</span>.<span style="color: #003366;">count</span><br />
&nbsp; &nbsp;<br />
&nbsp; &nbsp;<span style="color: #666666; font-style: italic;"># my New-Script and Get-PerformanceHistory functions use history IDs</span><br />
&nbsp; &nbsp;<span style="color: #666666; font-style: italic;"># So, put the ID of the command in, so we can get/invoke-history easier</span><br />
&nbsp; &nbsp;<span style="color: #666666; font-style: italic;"># eg: &quot;r 4&quot; will re-run the command that has [4]: in the prompt</span><br />
&nbsp; &nbsp;<span style="color: #660033; font-weight: bold;">$nextCommandId</span> <span style="color: #66cc66;">=</span> <span style="color: #333;">&#40;</span><span style="color: #0066cc; font-style: italic;">Get-<span style="font-style: normal;">History</span></span> <span style="color: #000066;">-count</span> <span style="color: #cc66cc;">1</span><span style="color: #333;">&#41;</span>.<span style="color: #003366;">Id</span> <span style="color: #66cc66;">+</span> <span style="color: #cc66cc;">1</span><br />
&nbsp; &nbsp;<span style="color: #666666; font-style: italic;"># Output prompt string</span><br />
&nbsp; &nbsp;<span style="color: #666666; font-style: italic;"># If there's an error, set the prompt foreground to &quot;Red&quot;, otherwise, &quot;Yellow&quot;</span><br />
&nbsp; &nbsp;<span style="color: #666699; font-weight: bold;">if</span><span style="color: #333;">&#40;</span><span style="color: #660033; font-weight: bold;">$err</span><span style="color: #333;">&#41;</span> <span style="color: #333;">&#123;</span> <span style="color: #660033; font-weight: bold;">$fg</span> <span style="color: #66cc66;">=</span> <span style="color: #009900;">&quot;Red&quot;</span> <span style="color: #333;">&#125;</span> <span style="color: #666699; font-weight: bold;">else</span> <span style="color: #333;">&#123;</span> <span style="color: #660033; font-weight: bold;">$fg</span> <span style="color: #66cc66;">=</span> <span style="color: #009900;">&quot;Yellow&quot;</span> <span style="color: #333;">&#125;</span><br />
&nbsp; &nbsp;<span style="color: #666666; font-style: italic;"># Notice: no angle brackets, makes it easy to paste my buffer to the web</span><br />
&nbsp; &nbsp;<span style="color: #0066cc; font-style: italic;">Write-<span style="font-style: normal;">Host</span></span> <span style="color: #009900;">&quot;[${Nesting}${nextCommandId}${Stack}]:&quot;</span> <span style="color: #000066;">-NoNewLine</span> <span style="color: #000066;">-Fore</span> <span style="color: #660033; font-weight: bold;">$fg</span><br />
&nbsp; &nbsp;<br />
&nbsp; &nbsp;<span style="color: #666699; font-weight: bold;">return</span> <span style="color: #009900;">&quot; &quot;</span><br />
<span style="color: #333;">&#125;</span></div>]]></content:encoded>
			<wfw:commentRss>http://huddledmasses.org/powershell-power-user-tips-a-better-prompt/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PowerShell Power User Tips: Current Directory</title>
		<link>http://huddledmasses.org/powershell-power-user-tips-current-directory/</link>
		<comments>http://huddledmasses.org/powershell-power-user-tips-current-directory/#comments</comments>
		<pubDate>Thu, 17 Apr 2008 00:36:28 +0000</pubDate>
		<dc:creator>Joel 'Jaykul' Bennett</dc:creator>
				<category><![CDATA[Huddled]]></category>
		<category><![CDATA[CurrentDirectory]]></category>
		<category><![CDATA[Path]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[PowerTips]]></category>
		<category><![CDATA[PUT]]></category>
		<category><![CDATA[Scripting]]></category>
		<category><![CDATA[Tips]]></category>

		<guid isPermaLink="false">http://HuddledMasses.org/powershell-power-user-tips-current-directory/</guid>
		<description><![CDATA[This is the second in an occasional series of tips for PowerShell users: short posts which don&#8217;t intend to give guidance, but merely a tip on a feature you may not be aware of, or maybe even answers to some of the recurring questions that come up in #PowerShell. Fixing the &#8220;Current Directory&#8221; problem The [...]]]></description>
			<content:encoded><![CDATA[	<p>This is the second in an occasional series of tips for PowerShell users: short posts which don&#8217;t intend to give guidance, but merely a tip on a feature you may not be aware of, or maybe even answers to some of the recurring questions that come up in #PowerShell.  </p>

	<h5>Fixing the &#8220;Current Directory&#8221; problem</h5>

	<p>The core of this tip is very simple: Windows tracks your application&#8217;s &#8220;current directory&#8221; ... and you can get and set this location using static methods of the <code>System.IO.Directory</code> class: <code>SetCurrentDirectory</code> and <code>GetCurrentDirectory</code>.</p>

	<p>The reason this is showing up as a Power User Tip is that PowerShell doesn&#8217;t set this environment setting when you navigate &#8212; it uses it&#8217;s internal &#8220;PSProvider&#8221; architecture, and doesn&#8217;t differentiate between whether you&#8217;re in a FileSystem location or a registry location, or even a third-party provider. So, it never actually changes the current directory, and any console command or .net method you call which uses the current directory will most likely be in the wrong place &#8212; like, for instance:</p>

	<div class="posh code posh" style="font-family:monospace;"><br />
<span style="color: #660033; font-weight: bold;">$sw</span> <span style="color: #66cc66;">=</span> <span style="color: #0066cc; font-style: italic;">New-<span style="font-style: normal;">Object</span></span> System.<span style="color: #003366;">IO</span>.<span style="color: #003366;">StreamWriter</span><span style="color: #333;">&#40;</span><span style="color: #009900;">&quot;NeatFile.txt&quot;</span><span style="color: #333;">&#41;</span><br />
<span style="color: #660033; font-weight: bold;">$sw</span>.<span style="color: #003366;">writeline</span><span style="color: #333;">&#40;</span><span style="color: #009900;">&quot;I could write a lot of neat stuff here!&quot;</span><span style="color: #333;">&#41;</span><br />
<span style="color: #660033; font-weight: bold;">$sw</span>.<span style="color: #003366;">close</span><span style="color: #333;">&#40;</span><span style="color: #333;">&#41;</span></div>

	<p>The problem is that now you don&#8217;t know where &#8220;NeatFile.txt&#8221; is &#8212; the &#8220;current directory&#8221; depends on how you launched PowerShell &#8212; most frequently it&#8217;s your <code>$Home</code> directory (equivalent to <code>Env:HOMEDRIVE + Env:HOMEPATH</code> &#8212; usually something like C:\Documents and Settings\YourName), but it could be your SystemRoot (C:\Windows) or the current directory of the app that launched PowerShell (eg: C:\Windows\System32 when you run it via &#8220;runas&#8221;). You can figure it out by running: <code>[IO.Directory]::GetCurrentDirectory()</code>.</p>

	<p>But here&#8217;s something more interesting: you can &#8220;fix&#8221; the problem by using <code>[IO.Directory]::SetCurrentDirectory</code>. There are a couple of catches, however: You can&#8217;t just use $pwd or <code>Get-Location</code> because you might be in the registry or some other location that&#8217;s not a Directory.  And you can&#8217;t just use <code>Get-Location -PSProvider FileSystem</code> because even though it returns the current <em>FileSystem</em> provider path, the FileSystem provider supports &#8220;fake&#8221; PSDrives (eg: you could create a Scripts: drive like <code>new-psdrive scripts filesystem &#34;$Home\Scripts&#34;</code>) and these aren&#8217;t actually supported by the .Net FileSystem.  Luckily, PowerShell includes a <code>Convert-Path</code> cmdlet which was created for this very purpose: converting a path from a Windows PowerShell path to a native path supported by the underlying provider.</p>

	<p>Without further ado, here&#8217;s a one-liner you can add to your prompt function:</p>

	<div class="posh code posh" style="font-family:monospace;"><br />
<span style="color: #003366; font-weight: bold;"><span style="color: #333;">&#91;</span>IO.<span style="color: #003366;">Directory</span><span style="color: #333;">&#93;</span></span>::<span style="color: #003366;">SetCurrentDirectory</span><span style="color: #333;">&#40;</span><span style="color: #333;">&#40;</span><span style="color: #0066cc; font-style: italic;">Convert-<span style="font-style: normal;">Path</span></span> <span style="color: #333;">&#40;</span><span style="color: #0066cc; font-style: italic;">Get-<span style="font-style: normal;">Location</span></span> <span style="color: #000066;">-PSProvider</span> FileSystem<span style="color: #333;">&#41;</span><span style="color: #333;">&#41;</span><span style="color: #333;">&#41;</span></div>

	<p> <img src='http://huddledmasses.org/wordpress/wp-includes/' alt='[new]' class='wp-smiley' />  <strong>Edit</strong>: You can do the same thing using the <code>System.Environment</code> class, and it turns out that the ProviderPath is a property of the PathInfo object, perhaps you&#8217;ll find this syntax simpler:</p>

	<div class="posh code posh" style="font-family:monospace;"><br />
<span style="color: #003366; font-weight: bold;"><span style="color: #333;">&#91;</span>Environment<span style="color: #333;">&#93;</span></span>::<span style="color: #003366;">CurrentDirectory</span><span style="color: #66cc66;">=</span><span style="color: #333;">&#40;</span><span style="color: #0066cc; font-style: italic;">Get-<span style="font-style: normal;">Location</span></span> <span style="color: #000066;">-PSProvider</span> FileSystem<span style="color: #333;">&#41;</span>.<span style="color: #003366;">ProviderPath</span></div>]]></content:encoded>
			<wfw:commentRss>http://huddledmasses.org/powershell-power-user-tips-current-directory/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

