EDUCBA

EDUCBA

MENUMENU
  • Free Tutorials
  • Free Courses
  • Certification Courses
  • 360+ Courses All in One Bundle
  • Login
Home Data Science Data Science Tutorials PowerShell Tutorial PowerShell Alias
Secondary Sidebar
PowerShell Tutorial
  • Functions
    • PowerShell Functions
    • PowerShell String Functions
    • powershell nslookup
    • PowerShell here string
    • PowerShell Wildcards
    • Regex in PowerShell
    • PowerShell not like
    • PowerShell Filter
    • PowerShell Sleep
    • PowerShell where
    • PowerShell join string
    • PowerShell Exit
    • PowerShell null
    • PowerShell Dictionary
    • PowerShell Location
    • PowerShell Start-Service
    • PowerShell is not digitally signed
    • PowerShell Uptime
    • PowerShell Create Directory
    • PowerShell Trim
    • PowerShell Join-Path
    • PowerShell Execution Policy
    • PowerShell SubString
    • PowerShell Format Table
    • PowerShell Import Module
    • PowerShell ForEach Object
    • PowerShell Alias
    • PowerShell Scheduled Task
    • PowerShell Convert String to Date
    • PowerShell Split String
    • PowerShell Multiline String
    • PowerShell MultiLine Comment
    • PowerShell Rename Folder
    • PowerShell Delete Folder
    • PowerShell String Replace
    • PowerShell join
    • PowerShell xcopy
    • PowerShell Base64
    • PowerShell Tail
    • PowerShell User List
    • PowerShell remove User from group
    • PowerShell JSON Format
    • PowerShell Send Mail
    • PowerShell Convert to String
    • PowerShell Start-Process
    • PowerShell change directory
    • PowerShell Open File
    • PowerShell Batch File
    • PowerShell ZIP
    • PowerShell unzip
    • PowerShell XML
    • PowerShell XML Parsing
    • Remote PowerShell
    • PowerShell Escape Character
    • PowerShell scriptblock
    • PowerShell Executable Location
    • PowerShell Import-CSV?
    • PowerShell Export CSV
  • Basics
    • PowerShell Restart Service
    • PowerShell comment
    • PowerShell Map Network Drive
    • PowerShell Append to File
    • PowerShell print
    • What is PowerShell
    • Uses Of Powershell
    • PowerShell Empire
    • PowerShell Parameter
    • PowerShell Stop Service
    • PowerShell Versions
    • How To Install PowerShell
    • PowerShell uninstall module
    • How to Use PowerShell?
    • PowerShell Logging
    • PowerShell Tools
    • PowerShell Commands
    • PowerShell Version Command
    • PowerShell Administrator
    • PowerShell Modules
    • PowerShell Registry
    • PowerShell block Comment
    • PowerShell Verbs
    • PowerShell list
    • PowerShell add user to group
    • PowerShell Write to Console
    • Variable in PowerShell
    • PowerShell New Line
    • PowerShell prompt for input
    • PowerShell File Extension
    • Powershell Remotesigned
    • PowerShell Write to File
    • PowerShell Ping
    • PowerShell wget
    • PowerShell Global variable
    • PowerShell Get-ADGroup
    • Array in PowerShell
    • PowerShell Multidimensional Array
    • PowerShell Array of Strings
    • PowerShell? join array
    • Useful PowerShell Scripts
    • String in PowerShell
    • PowerShell Switch Statement
    • PowerShell Function Parameters
    • PowerShell vs PowerShell ISE
    • PowerShell test-connection
    • PowerShell Test-NetConnection
    • PowerShell GUI
    • PowerShell Variable in String
    • PowerShell Active Directory
  • Variables
    • PowerShell Variables
    • PowerShell Environment Variables
    • PowerShell set environment variable
    • Hashtable in PowerShell
    • Set Variable in PowerShell
  • Operators
    • PowerShell Operators
    • Comparison Operators in PowerShell
    • Logical Operators in PowerShell
    • PowerShell Boolean
    • PowerShell Like Operator
  • cmdlet
    • PowerShell Wait
    • PowerShell Match
    • cmdlets in PowerShell
    • Start PowerShell from cmd
    • Add-Content in PowerShell
    • Get Help in PowerShell
    • PowerShell Copy-Item
    • PowerShell Remove-Item
    • PowerShell Move-Item
    • Get Command in PowerShell
    • PowerShell Run Command
    • Windows PowerShell ISE
    • Windows Powershell Commands
    • WinRM PowerShell
    • PowerShell Date
    • Powershell Write-Host
    • PowerShell Get-ChildItem
    • PowerShell Sort-Object
    • PowerShell Where Object
    • PowerShell Set-Content
    • PowerShell Set-Location
    • PowerShell Invoke-Command
    • PowerShell Invoke-Webrequest
    • PowerShell Get-Location
    • PowerShell Get-Date
    • PowerShell Get-Service
    • PowerShell Test-Path
    • Powershell Module Path
    • PowerShell Out-File
    • PowerShell if File Exists
    • Powershell Copy File
    • PowerShell Delete File
    • PowerShell New-Item
    • PowerShell Rename-Item
    • PowerShell ComputerName
    • PowerShell Get-Content
    • PowerShell Get-Item
    • PowerShell Get-ADUser
    • PowerShell Grep
    • PowerShell Concatenate String
    • PowerShell Get-Process
    • PowerShell Count
    • PowerShell pause
  • Control Statements
    • If Statement in PowerShell
    • If Else in PowerShell
    • Else If in PowerShell
    • Loops in PowerShell
    • For loop in PowerShell
    • PowerShell While Loop
    • PowerShell do while
    • PowerShell Loop through Array
    • PowerShell add to array
    • PowerShell ForEach Loop
    • PowerShell Break
    • PowerShell Continue
    • Switch Case in PowerShell
    • PowerShell If-Not
    • Try-catch in PowerShell
  • Interview Questions
    • PowerShell Interview Questions

Related Courses

Shell Scripting Course

All in One Data Science Courses

Data Visualization Courses

PowerShell Alias

By Priya PedamkarPriya Pedamkar

powershell alias

Introduction to PowerShell Alias

Alias in PowerShell allows us to define short names for commands so that it will be easy for us to remember and write it, we can also create alias for any executable files.

When we write any command and use the Set-Alias along with the name which we wanted to use for shorter names for the commands than in memory it will hold the command full details inside the memory with the Alias name. At any time if we wanted to use the defined shorter name for the alias we can call it with Get-Alias. We can use Set-Alias and Get-Alias commands for setting and getting the actual command with Alias. We also have an available command for removing and any existing Alias. We can overwrite the existing Alias if we wanted to do any modification into the existing Alias.

How to Create PowerShell Alias?

To create an alias we need to use the Set-Alias command. This command allows us to set the alias name for the given function. Suppose we wanted to see the all list of available packages than we can use the command Get-Package but here we will create an alias for Get-Package. See the example below, here in this example we are setting an alias name for Get-Package with “pkg” name and in the next line, we are getting details of it by Get-Alias with “pkg” name.

We can use below syntax for setting an alias in powershell.

Start Your Free Data Science Course

Hadoop, Data Science, Statistics & others

All in One Data Science Bundle(360+ Courses, 50+ projects)
Python TutorialMachine LearningAWSArtificial Intelligence
TableauR ProgrammingPowerBIDeep Learning
Price
View Courses
360+ Online Courses | 50+ projects | 1500+ Hours | Verifiable Certificates | Lifetime Access
4.7 (86,471 ratings)

Syntax:

Set-Alias
[-Name] <shorter name for command>
[-Value] <actual command which we wanted to shorter>
[-Description <String description of what command will do>] [-Option <access level of command like readonly ,read and write both etc>] [-PassThru<details of object through which it is going through>] [-Scope <string value of scope like local or global>] [-Force<we can use it for forced for hidden files>] [-WhatIf<display what will happen without actual impact>] [-Confirm<display a prompt for your confirmation>]

Below is the example to set an alias in PowerShell.

Example:

Set-Alias -Name pkg -Value Get-Package
Get-Alias pkg

PowerShell Alias-1.1

In the above example, we have set an Alias to the command Get-package, and with the help of Get-Alias on the defined alias name, we are able to get the alias details.

How to Access and Modify PowerShell Alias?

Here we discuss how to access and modify PowerShell alias.

Accessing Alias in PowerShell

To access Alias in PowerShell we can use a command called Get-Alias, it will allow us to get the name set by a command called Set-Alias. Below is an example to get the alias name. To access any defined Alias in PowerShell we can use below format,

Syntax:

Get-Alias
[[-Name] <array of string name which we set in alias>] [-Exclude <We can exclude with writing array of string>] [-Scope <String value of scope like local or global>]

Example:

Set-Alias -Name TP -Value ./ranjan/ranjan1
Get-Alias TP

Output:

PowerShell Alias-1.2

Modify Alias

In PowerShell, if we wanted to modify any alias then we can overwrite it again with another value and it will be modified, which will change the older name of the alias. In general, there is not any available command for modification we need to override the existing alias value with the new one.

Setting an alias and getting it.

Example:

Set-Alias -Name TPF -Value ./ranjan/ranjan1
Get-Alias TPF

Output:

PowerShell Alias-1.3

Modifying existing alias with a new value.

Example:

Set-Alias -Name TPF -Value ./ranjan/ranjan2
Get-Alias TPF

Output:

Output-1.4

In the above example first, we set the value for the Alias “TPF” as the path “/ranjan/ranjan1” and in the next line we change it to “ranjan/ranjan2” by rewriting the same command with different values.

How to Remove PowerShell Alias?

We can remove any Alias with the PowerShell command called Remove-Alias. This command removes the Alias with the name which we passed for it. See the below format to remove Alias in PowerShell.

Syntax:

Remove-Alias
[-Name] <String name for the Alias which we want to remove>
[-Scope <String scope name like local>] [-Force<In case we do not have permission or it is hidden than we can run this command to work>]

Set and get the alias,

Example:

Set-Alias -Name TPF -Value ./ranjan/ranjan1
Get-Alias TPF

Output:

Output-1.5

Remove the alias defined above,

Example:

Remove-Alias -Name TPF //removing the the Alias “TPF”
Get-Alias TPF//will through an error as we have removed the Alias “TPF”

Output:

Output-1.6

On running the command get-Alias it will be through an error as we have already removed the Alias “TPF” and we are trying to fetch its value.

Importance

Let’s understand one thing when we will be writing any big script at that time our code goes very long and maintenance is very hard in that case. Also, the readability of code will not be very good. For example, if we wanted to write some command related to all running processes than in PowerShell we will use “Get-process” but with the help of Alias concept in PowerShell, we can write the same command in more readable like “process-list” or “PL”.by writing “PL” instead of writing “Get-process” we are able to save few characters. Here the length of “Get-process” is 11 and the length of “PL” is two so we are able to save 9 letters here.

In general, we can define a few points for its importance they are given below.

  • Shorter the Code: Because it is in our hands what name we wanted to give to the PowerShell command for an alias, so we can give smaller names to them, which can make our code less than half of the code without an alias.
  • More Readable the Code: Many commands do not make very meaningful names according to the work they perform, so in such a situation we can define more readable Alias name for commands so that others and we also can easily be able to understand the code.
  • Easier to Maintenance: Because code is more readable and understandable, other people who are going to some work on an existing script they can easily understand each line and their meaning

Recommended Articles

This is a guide to PowerShell Alias. Here we discuss the Introduction and how to create PowerShell alias and how to access and modify PowerShell alias with its importance. You may also look at the following articles to learn more –

  1. Examples to Implement PowerShell Get-Date
  2. Shortcuts for Get Help in PowerShell
  3. Explanation on cmdlets in PowerShell
  4. Complete Guide to Python Import Module
Popular Course in this category
PowerShell Training (2 Courses, 1 Project)
  2 Online Courses |  1 Hands-on Project |   4+ Hours |  Verifiable Certificate of Completion
4.5
Price

View Course

Related Courses

Shell Scripting Training (4 Courses, 1 Project)4.9
All in One Data Science Bundle (360+ Courses, 50+ projects)4.8
Data Visualization Training (15 Courses, 5+ Projects)4.7
0 Shares
Share
Tweet
Share
Primary Sidebar
Footer
About Us
  • Blog
  • Who is EDUCBA?
  • Sign Up
  • Live Classes
  • Corporate Training
  • Certificate from Top Institutions
  • Contact Us
  • Verifiable Certificate
  • Reviews
  • Terms and Conditions
  • Privacy Policy
  •  
Apps
  • iPhone & iPad
  • Android
Resources
  • Free Courses
  • Database Management
  • Machine Learning
  • All Tutorials
Certification Courses
  • All Courses
  • Data Science Course - All in One Bundle
  • Machine Learning Course
  • Hadoop Certification Training
  • Cloud Computing Training Course
  • R Programming Course
  • AWS Training Course
  • SAS Training Course

ISO 10004:2018 & ISO 9001:2015 Certified

© 2022 - EDUCBA. ALL RIGHTS RESERVED. THE CERTIFICATION NAMES ARE THE TRADEMARKS OF THEIR RESPECTIVE OWNERS.

EDUCBA
Free Data Science Course

SPSS, Data visualization with Python, Matplotlib Library, Seaborn Package

*Please provide your correct email id. Login details for this Free course will be emailed to you

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA Login

Forgot Password?

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA
Free Data Science Course

Hadoop, Data Science, Statistics & others

*Please provide your correct email id. Login details for this Free course will be emailed to you

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you

By signing up, you agree to our Terms of Use and Privacy Policy.

Let’s Get Started

By signing up, you agree to our Terms of Use and Privacy Policy.

This website or its third-party tools use cookies, which are necessary to its functioning and required to achieve the purposes illustrated in the cookie policy. By closing this banner, scrolling this page, clicking a link or continuing to browse otherwise, you agree to our Privacy Policy

Loading . . .
Quiz
Question:

Answer:

Quiz Result
Total QuestionsCorrect AnswersWrong AnswersPercentage

Explore 1000+ varieties of Mock tests View more