Autorun for PowerShell

27,861

You would set up a profile. All commands in the profile are executed every time you start a PowerShell session. There are different profiles for user, machine, etc. As described on MSDN:

Understanding the Profiles

You can have four different profiles in Windows PowerShell. The profiles are listed in load order. The most specific profiles have precedence over less specific profiles where they apply.

  • %windir%\system32\WindowsPowerShell\v1.0\profile.ps1
    This profile applies to all users and all shells.

  • %windir%\system32\WindowsPowerShell\v1.0\Microsoft.PowerShell_profile.ps1
    This profile applies to all users, but only to the Microsoft.PowerShell shell.

  • %UserProfile%\My Documents\WindowsPowerShell\profile.ps1
    This profile applies only to the current user, but affects all shells.

  • %UserProfile%\My Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1
    This profile applies only to the current user and the Microsoft.PowerShell shell.

Share:
27,861

Related videos on Youtube

Admin
Author by

Admin

Updated on September 18, 2022

Comments

  • Admin
    Admin over 1 year

    I have created some aliases (doskey), saved them to a file and added AutoRun value (pointing that file) for cmd.exe at:

    HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Command Processor
    

    I would like to do the same with PowerShell. Is there any registry value for PowerShell which points to commands that will be run each time I start PowerShell?

    • Admin
      Admin almost 11 years
      I hate using doskey. I find that just putting those aliases in my script (as function)s works better.
  • Knuckle-Dragger
    Knuckle-Dragger over 10 years
    notepad $profile
  • Chris F Carroll
    Chris F Carroll almost 9 years
    if you have no $profile, see how to create one here: technet.microsoft.com/en-us/library/ff461033.aspx
  • Shivam Anand
    Shivam Anand about 2 years
    For current user the profile is %UserProfile%\Documents\WindowsPowerShell\Microsoft.PowerShe‌​ll_profile.ps1