<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.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>Fun with Paths</title><link>http://blogs.msdn.com/b/powershell/archive/2007/04/27/fun-with-paths.aspx</link><description>Jeffrey wrote a great post for wizards about the scope of variables in PowerShell, so to maintain balance, I thought I'd weigh in with one for newbies. (Although, to be honest, Jeffrey's description is clear enough for the rest of us.) 
 
 There are</description><dc:language>en-US</dc:language><generator>Telligent Evolution Platform Developer Build (Build: 5.6.50428.7875)</generator><item><title>re: Fun with Paths</title><link>http://blogs.msdn.com/b/powershell/archive/2007/04/27/fun-with-paths.aspx#10301956</link><pubDate>Mon, 07 May 2012 20:18:20 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10301956</guid><dc:creator>Huffman</dc:creator><description>&lt;p&gt;I found a instance that I need to find the filename from the absolute path that was not a local path. In this case I found I can use &amp;quot;Split&amp;quot; resolve the filename.&lt;/p&gt;
&lt;p&gt;##Example: &lt;/p&gt;
&lt;p&gt;$strName = &amp;quot;D:\Microsoft SQL Server\MSSQL.1\MSSQL\ABC_DBA.mdf&amp;quot; &lt;/p&gt;
&lt;p&gt;$filename = $strName.split(&amp;quot;\&amp;quot;)[(($strName.split(&amp;quot;\&amp;quot;).count)-1)]&lt;/p&gt;
&lt;p&gt;##To break this down and explain...(but note only 2 lines are needed to get the outcome)&lt;/p&gt;
&lt;p&gt;$strName = &amp;quot;D:\Microsoft SQL Server\MSSQL.1\MSSQL\ABC_DBA.mdf&amp;quot; &lt;/p&gt;
&lt;p&gt;##get the count of splits (This returns &amp;quot;5&amp;quot;)&lt;/p&gt;
&lt;p&gt;$strName.split(&amp;quot;\&amp;quot;).count&lt;/p&gt;
&lt;p&gt;##this would be the manual way to return the exact part of the array that gives us the filename&lt;/p&gt;
&lt;p&gt;$strName.split(&amp;quot;\&amp;quot;)[4]&lt;/p&gt;
&lt;p&gt;##We will now insert the count(5) and subtract 1 in place of the 4 (because the array begins with 0, not 1)&lt;/p&gt;
&lt;p&gt;$strName.split(&amp;quot;\&amp;quot;)[(($strName.split(&amp;quot;\&amp;quot;).count)-1)]&lt;/p&gt;
&lt;p&gt;##lastly i assign the above line into a variable called filename&lt;/p&gt;
&lt;p&gt;$filename = $strName.split(&amp;quot;\&amp;quot;)[(($strName.split(&amp;quot;\&amp;quot;).count)-1)]&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10301956" width="1" height="1"&gt;</description></item><item><title>re: Fun with Paths</title><link>http://blogs.msdn.com/b/powershell/archive/2007/04/27/fun-with-paths.aspx#8461570</link><pubDate>Tue, 06 May 2008 01:13:35 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8461570</guid><dc:creator>Dunkin'</dc:creator><description>&lt;p&gt;You can eliminate the current dir from the path by calling split-path -parent twice.&lt;/p&gt;
&lt;p&gt;Example:&lt;/p&gt;
&lt;p&gt; &amp;nbsp; $ScriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path&lt;/p&gt;
&lt;p&gt; &amp;nbsp; $ScriptParentDir = Split-Path -Parent $ScriptDir&lt;/p&gt;
&lt;p&gt;$MyInvocation.MyCommand.Path returns the path to the script file.&lt;/p&gt;
&lt;p&gt;If you just need the parent directory you can shorten it to the following:&lt;/p&gt;
&lt;p&gt; &amp;nbsp; $ScriptParentDir = Split-Path -Parent ( Split-Path -Parent $MyInvocation.MyCommand.Path )&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8461570" width="1" height="1"&gt;</description></item><item><title>re: Fun with Paths</title><link>http://blogs.msdn.com/b/powershell/archive/2007/04/27/fun-with-paths.aspx#7912632</link><pubDate>Wed, 27 Feb 2008 04:54:10 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:7912632</guid><dc:creator>Dennis</dc:creator><description>&lt;p&gt;Nice article for a newbie like me.&lt;/p&gt;
&lt;p&gt;Although when I tried this using a UNC path their is a problem. $pwd doesnt just return the current UNC path but instead returns&lt;/p&gt;
&lt;p&gt;Microsoft.PowerShell.Core\FileSystem::\\ServerName\ShareName&lt;/p&gt;
&lt;p&gt;However the FullName property returns just&lt;/p&gt;
&lt;p&gt;\\ServerName\ShareName\FileName&lt;/p&gt;
&lt;p&gt;As such the $pwd.path.length is incorrect when executing&lt;/p&gt;
&lt;p&gt;$_.FullName.SubString($pwd.path.length)&lt;/p&gt;
&lt;p&gt;As this also will count the length of &lt;/p&gt;
&lt;p&gt;Microsoft.PowerShell.Core\FileSystem::&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=7912632" width="1" height="1"&gt;</description></item><item><title>re: Fun with Paths</title><link>http://blogs.msdn.com/b/powershell/archive/2007/04/27/fun-with-paths.aspx#2575821</link><pubDate>Sat, 12 May 2007 21:08:39 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:2575821</guid><dc:creator>peter hasan</dc:creator><description>&lt;p&gt;The next command will give you all available aliases:&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; Get-Command -CommandType Alias&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=2575821" width="1" height="1"&gt;</description></item></channel></rss>