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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With