Create an alias for the path

Is it possible in PowerShell to create an alias for a path?

For example: I have to write all the time

PS PS C:\Users\Jacek>cd C:\windows\microsoft.net\framework\v4.0.30319

      

I will be glad if I can write

PS PS C:\Users\Jacek>cd dotNet4path

      

+1


source to share


3 answers


You can just create a variable in your powershell profile with this path as value.

Then all you have to do is something like

cd $dotNet4path

      



To add something to your profile, enter $ profile, into the powershell window and it will display the path to the powershell profile file. Create it if it doesn't exist.

Then put this line in a file, save and restart powershell.

$dotNet4path = "C:\windows\microsoft.net\framework\v4.0.30319"

      

+2


source


you can use an alias to execute a custom function (you can do this in your profile) or use psdrive:



function path2dotNet{cd "C:\Users\Jacek>cd C:\windows\microsoft.net\framework\v4.0.30319"}  
Set-Alias dot4 -Value path2doc

New-PSDrive dotnet -PSProvider FileSystem -Root "C:\Users\Jacek>cd C:\windows\microsoft.net\framework\v4.0.30319" 
cd dotnet:

      

+2


source


You can use your powershell profile to store the path in a variable:

Add-Content -Value '$dotNet4path = C:\windows\microsoft.net\framework\v4.0.30319' -Path $profile -Force

      

If you restart your PowerShell you can type

cd $dotNet4path

      

0


source







All Articles