How do I make PowerShell run as administrator start in my home directory?

7,878

If you always use a shortcut you can just add the arguments:

-NoExit -Command "cd ~"

If you want this to always execute you can make a profile, to do this create the file (and missing folders on the path):

%userprofile%\Documents\WindowsPowerShell\profile.ps1

And place the cd command (cd ~) inside it.

To allow the scripts execution on startup you need to change the execution policy to be less restrictive or bypass it.

To bypass you can pass an argument when starting powershell:

-ExecutionPolicy Bypass

To change the policy run powershell as admin and execute:

Set-Executionpolicy RemoteSigned

Do this at your own risk of course. If you did you will always end up in your home folder on startup.

Share:
7,878

Related videos on Youtube

Mike Makuch
Author by

Mike Makuch

Updated on September 18, 2022

Comments

  • Mike Makuch
    Mike Makuch over 1 year

    Whenever I run PowerShell as administrator, it starts in C:\WINDOWS\system32\WindowsPowerShell\v1.0. How do I make it start in my user's home directory instead? My $HOME has the expected value, i.e., C:\Users\<account>. Whenever I run PowerShell without administrative privileges it starts up in $HOME.

    • Admin
      Admin over 12 years
      Do you only want this to take effect when you open the PS CLI, or system-wide (ie: when scripts are run, etc.)?
    • Admin
      Admin over 12 years
      @techie007 When I open the CLI. Hadn't actually considered the script case.
  • Mike Makuch
    Mike Makuch over 12 years
    Do you know why PowerShell defaults to another directory (than $HOME) when run with administrative privileges? Also, can I prevent "cd ~" from echoing the directory?
  • H.B.
    H.B. over 12 years
    @aknuds1: I do not know why it starts there, possibly because the system files is where the admin most likely wants to do something. What do you mean by "echoing the directory", cd should not create any output.
  • Mike Makuch
    Mike Makuch over 12 years
    Actually, for me, cd echoes the directory. I've tested by putting echo statements before and after the cd command in profile.ps1, and have that way verified this behaviour.
  • H.B.
    H.B. over 12 years
    Interesting, wonder why it's different...
  • Jeff Martin
    Jeff Martin over 5 years
    i liked the -noexit -command for my shortcut over putting a CD in my profile script... vscode runs my profile script but was moving to my home directory rather than the folder of the project i was in