Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I have created a powershell cmdlet and assigned it to an Alias. How do I do this automatically every time powershell launches? (i.e. so I don't have to re-assign the alias every time)

share|improve this question

1 Answer 1

up vote 3 down vote accepted

Create a profile.

This is a .ps1 script that will be run before you get the prompt.

You can have three per-user profiles, all in the WindowsPowerShell folder under your default documents folder.

  • profile.ps1: always run first.
  • Microsoft.PowerShellISE_profile.ps1: run second for ISE.
  • Microsoft.PowerShell_profile.ps1: run second for console instance.

The second file to be run is given by $Profile in the applicable instance (and will give you the folder for all of them).

See help about_profiles for more details.

share|improve this answer
    
Fantastic. Thanks for the answer. I couldn't open my Documents&Settings in Windows7 for some reason, but I managed to edit profile.ps1 in c:\windows\system32\windowsPowershell\v1.0\ Works like a charm. –  willem Apr 22 '10 at 9:49
    
That's because "Documents and Settings" isn't a folder in Windows Vista/7. It's a symlink (not accessible using Explorer) that points to "Users" folder. –  Hello71 Jun 27 '10 at 16:01
    
@willem, @Hello71: To change to your user profile folder: pushd (split-path $profile). If the folder doesn't exist this will fail, so you might need: md (split-path $profile) –  Richard Jun 28 '10 at 8:04
    
the global one no longer works in Win8. –  Warren P Nov 11 '12 at 15:58

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.