Shortcut for Directory – PowerShell

It’s been for a while since I started using PowerShell for some operations. It might seem complicated at the beginning but if you be patient and keep learning, it makes so many tasks easy for you, especially for .NET developers.

To create aliases for the commands:

New-Alias show Get-ChildItem 

And when you use it

 show 

It will list the files & folders in the current directory, just like DIR or LS.

When you close the current PowerShell session, this alias will be removed. In order to make it permanent, you will need to create a file with the name Microsoft.PowerShell_profile.ps1 under PSConfiguration folder under  Windows PowerShell profile folder. To learn your Windows PowerShell profile folder, use

Get-Variable profile | Format-List

So the location of the new file would be like  >

Windows PowerShell profile folder/PSConfiguration/Microsoft.PowerShell_profile.ps1

If you create/edit this file and add the new aliases to it, they will be available for all sessions.

There is one issue about creating an alias for navigating folders – it is not possible. Aliases are just for command, in order to navigate a directory, you will need to create a function in the Microsoft.PowerShell_profile.ps1 file.

function myproject { set-location "C:\Users\Dude\Desktop\MyImportanProject" }
function desktop { set-location "C:\Users\Dude\Desktop\" }

After you save this functions in the file and reopen PowerShell, you can use the commands by just typing 

myproject
desktop

Information provided here is a summary from official support page here >> https://technet.microsoft.com/en-us/library/ee176913.aspx

Advertisements

#command-line, #directory-alias-powershell, #powershell, #powershell-basics, #powershell-for-developers, #shorcut-directory-powershell