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)

link|improve this question

75% accept rate
feedback

1 Answer

up vote 2 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.

link|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
feedback

Your Answer

 
or
required, but never shown

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