Aliases in PowerShell - how to obtain them, after restarting PowerShell

Aliases are very cool stuff. All cmdlets (command in PowerShell - dll with power of .NET) contains name like get for some result from a environment, add to add some values to memoria or set to set a variable and so on. Alias are short names for the integrated or your own cmdlets.

Example:

We all use help to see, what member or properties are avaible from an cmdlet. A command to get help is get-help. I, on other hand, dont like long names, so, i used alias to shorten the name and to simply memorize it.

set-alias help get-help
 

Nice. I was starting to write a lot of aliases. Then, i updated my machine, so restart was neccessary. After reboot, i started the power shell and my aliases were gone. Hm. Then i discovered the way to save them. Basicly, there are 2 ways:

  • in your profile
    • create a file, named Profile.ps1 in your PowerShell directory (hint: C:\WINDOWS\system32\windowspowershell\v1.0 ). If you allready have it, then open it. Then write your aliases each in a line.
    • Save the file and restart your PowerShell window
  • in a file (i like this one, because it is portable. Like, i can send my aliases to my friend and he can use it anyway he like it)
    • create a file with a name of your choice with extension ps1 in a PowerShell directory.Write your aliases.
    • save the file
    • open Profile.ps1 file, add full path to your aliases in a line (dont matter where), and use quotation marks like this "C:\WINDOWS\system32\windowspowershell\v1.0\aliases.ps1"
    • save the file Profile.ps1
    • restart the PowerShell
Now you will have all the aliases avaible to you.
Avtor: bojanv, objavljeno na portalu SloDug.si (Arhiv)

Leave a comment

Please note that we won't show your email to others, or use it for sending unwanted emails. We will only use it to render your Gravatar image and to validate you as a real person.

Anonymous
Anonymous - četrtek, 14. december 2006

PSCX is a extension for Power Shell (previously named Monad). It contains useful set of additional cmdlets,