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.
-
Do you only want this to take effect when you open the PS CLI, or system-wide (ie: when scripts are run, etc.)?– Ƭᴇcʜιᴇ007Commented Nov 14, 2011 at 14:55
-
@techie007 When I open the CLI. Hadn't actually considered the script case.– aknuds1Commented Nov 14, 2011 at 15:06
1 Answer
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.
-
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?– aknuds1Commented Nov 15, 2011 at 13:25
-
@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.– brunnerhCommented Nov 15, 2011 at 16:15
-
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.– aknuds1Commented Nov 15, 2011 at 19:49
-
-
1i 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 Commented Aug 16, 2018 at 20:06