Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create a folder alias in PowerShell

I know that I can create variable that represents a folder path in my profile. For example,

$here = Split-Path -Parent $MyInvocation.MyCommand.Path

Is there an easy way to create an alias to a directory in PowerShell?

Create an alias

PS> Create-FolderAlias -name $foo -path "C:\Program Files"

Create an alias based on another alias

PS> Create-FolderAlias -name $bar -path $foo + "\Microsoft"

Use alias as expected

PS> cd $foo

It would be nice if these aliases would be persisted between sessions.

like image 430
craig Avatar asked May 16 '13 21:05

craig


1 Answers

You can turn a folder into a new powershell drive with New-PSDrive

New-PSDrive foo filesystem 'C:\Program Files'
New-PSDrive bar filesystem 'foo:\Microsoft'
cd foo:

To persist between sessions you could add them to your profile script ($profile).

But of course you can also cd to a folder from a variable

$foo = 'C:\Program Files'
$bar = Join-Path $foo 'Microsoft'
cd $foo
like image 159
Lars Truijens Avatar answered Oct 02 '22 08:10

Lars Truijens