Create Folder Alias ​​in PowerShell

I know that I can create a variable representing the path to the folder in my profile. For instance,

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

Is there an easy way to create an alias in 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 an alias as expected

 PS> cd $foo 

It would be nice if these aliases persisted between sessions.

+4
source share
1 answer

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 can add them to your script profile ($ 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 
+10
source

Source: https://habr.com/ru/post/1481264/


All Articles