- Trending Categories
- Data Structure
- Operating System
- C Programming
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to create PowerShell alias permanently?
PowerShell alias can be created permanently by 2 methods below.
a) Import / Export Alias
To export all the aliases, you need to use Export-Alias cmdlet. When you use this command it will ask you the path for the file to import.
To export the newly created alias, you need to give alias name and the name for the export, so later you can import it with the same name.
In the below example, we have created alias name Edit for the Wordpad and we will export all the aliases with the name Alias1, so the newly created alias will also be stored and when you want to import your newly created aliases you need to write Import-Alias command.
Now, we will export all the aliases.
Export-Alias -Path D:\Temp\Alias1
You can check the exported aliases and manipulate them as well with the proper format.
Next, whenever you run the new PowerShell console, you won’t find the new aliases so you need to import the exported aliases.
Import-Alias -Path D:\Temp\Alias1
But when you run the above command, you will get an error that inbuilt aliases are already existed but we have remediation for it, we can use –Force parameter to forcefully overwrite those aliases.
Import-Alias -Path D:\Temp\Alias1 -Force
Now you see the newly created aliases as well in the PowerShell console.
b) Startup Profile Script.
Another option but easier than Import/Export option is to create a profile script so every time PowerShell opens it loads a startup profile and all the commands and scripts are loaded which resides inside that profile folder.
Here, we will create a profile file Profile.ps1 using below command on the $PROFILE path of your PowerShell.
notepad $((Split-Path $profile -Parent) + "\profile.ps1")
The above command will prompt to the user to create Profile1.ps1 on the $Profile path if it doesn’t exist and if it is already created then it will open the file to allow the user to manipulate.
Once a file is opened, edit the file to set your aliases. Here we will set two aliases in the file. Type the following two commands in notepad and save it.
Set-Alias edit notepad.exe Set-Alias edit1 "C:\Program Files\Windows NT\Accessories\wordpad.exe"
Launch the PowerShell console again and when you type edit, it will open Notepad and when you type edit1, it will open Wordpad.
With this simple method, you can add as many aliases in the profile script and launch them through the PowerShell console.
- How to create new alias with PowerShell?
- How to overwrite or remove PowerShell alias?
- How to use function Alias in PowerShell?
- What is an alias in PowerShell?
- How to use an alias() for the parameter in PowerShell?
- How to get/resolve the command from the alias in PowerShell?
- How to create an ALIAS TAB2 for DB2 table TAB1?
- How to set sql_mode permanently in MySQL?
- How to create an array in PowerShell?
- How to create a Dictionary in PowerShell?
- How to disable action bar permanently in Android?
- How to Delete Data Permanently from a PC?
- How to create a Hash Table in PowerShell?
- How to create a User Menu in PowerShell?
- How to create a temporary file using PowerShell?