Set alias command in powershell to make your life easier

Photo by Ilya Pavlov on Unsplash

When we are using VS Code for development, it also comes with powershell as the default terminal.

Sometimes we have to run commands in the terminal, and the commands maybe long and easily make typo, for example:

kubectl

kudectl

You have to spend some amount of time to figure it out.

Also, setting alias command can save your time from typing a long command to just a few characters.

Create permanent PowerShell Aliases

First, open VS Code and type below command on the terminal.

Get-Variable profile | Format-List

Value shows the path of your powershell profile. If you open fire explorer and follow the path, you may find out that the folder is not exist. If that is the case, we need to create the folder WindowsPowerShell and the file Microsoft.PowerShell_profile.ps1 .

After that, it’s time for us to set some alias commands, use editor (e.g. notepad) to open Microsoft.PowerShell_profile.ps1

Create new alias command by inputting Set-Alias <name> <value>.

For example: Set-Alias k kubectl.

Then save the file and reopen VS Code. Input k on the terminal.

It is equal to the command kubectl.

However, Set-Alias are just that — aliases for command names — not command names plus arguments. For example, we cannot set alias like this:

kubectl describe pod [pod name]

Set-Alias kdp kubectl describe pod

In this case, we need to use function :

function <alias name>{
<command plus arguments> $args
}

open Microsoft.PowerShell_profile.ps1 and add:

Set-Alias k kubectlfunction kdp {
k describe pod $args
}

Save and reopen VS Code.

Now, when we input kdp posts it is equivalence to

kubectl describe pod posts

You should always make your own list of alias commands to save time and get rid of typo.

--

--

--

Hi, I am interested in IT field including front-end, back-end, database, networking.

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

JSON Web Token Authentication with ASP.NET Core 2.0

Ruby Play Network May Community Update

The use of Strategy Design Pattern when developing a payment system in Laravel

Some Simple Python: List Comprehensions

Setup Hasura/Local-Development

Tutuapp Com Minecraft

Free

How to run Azure Disk Loss Experiment in LitmusChaos

Setting up Rails 6 with React

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Frankie

Frankie

Hi, I am interested in IT field including front-end, back-end, database, networking.

More from Medium

GitHub and the command line: “Gitting” better at coding:

Cute cat looking at camera

Quick reference guide to GIT COMMANDS

git commands that I find useful

Using Git Like A Pro