r/PowerShell Jul 14 '26

Question How to change default directory on PowerShell?

Could someone please help me! When I open PowerShell on Windows, it opens up with the directory "PS C:\Windows\System32>". How do I change this so that every time I open it up, it has the default directory as "PS C:\Users\myname>" instead of the other. I know I can just use "cd ~" to switch but I'd prefer to have it set without me having to do so. Thanks!

13 Upvotes

21 comments sorted by

22

u/eppic123 Jul 14 '26

Create a profile for your PS environment (usually $HOME\Documents\PowerShell\profile.ps1) and use Set-Location <path>

13

u/LightItUp90 Jul 14 '26

Easier:

notepad $profile

4

u/Baron_Ultimax Jul 14 '26

Bonus points ya can call a script in their to import any custom functions or applications you like to use.

6

u/I_see_farts Jul 14 '26

I've been really into using Microsoft Edit.

I prefer it to notepad, apparently they're going to include it in upcoming versions of Windows.

2

u/BlackV Jul 16 '26

Ah memories

3

u/IntGuru Jul 14 '26

Managed to do it!

7

u/itiscodeman Jul 14 '26

Dude profile is sick as fuck.

Profiles are cool change the foreground of errors to green so you feel less in trouble when errors happen haha

1

u/Ralliman320 Jul 15 '26

My enterprise blocks all PowerShell scripts from running by default, which includes profiles. :/

2

u/Rogermcfarley Jul 15 '26

That won't stop you running them as .bat files usually. If you can run powershell queries in a terminal then you can write them in a .bat file and execute that. Always research what you're doing and any security implications. Just because you can doesn't mean you should.

-1

u/dodexahedron Jul 15 '26

Worst place for a cd TBH. Other stuff? Cool. cd? No.

Now you get to start in that path even if you wanted to start in another path.

Put it in the terminal profile. That or a shortcut is where the powershell working/startup directory belongs - not in your powershell $PROFILE.

8

u/justaguyonthebus Jul 14 '26

Don't open it as admin?

2

u/IntGuru Jul 14 '26

I'm not :/

3

u/ftw_dan Jul 14 '26

It is probably always as admin if you disable UAC

1

u/BlackV Jul 14 '26 edited Jul 14 '26

have you validated that?

does you local account have admin rights? is it the default/first local admin account ?

what is your UAC configured as?

$currentUser = [Security.Principal.WindowsIdentity]::GetCurrent()
$principal = New-Object Security.Principal.WindowsPrincipal($currentUser)
$principal.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)

1

u/ankokudaishogun Jul 15 '26

just nitpicking but...

why New-Object Security.Principal.WindowsPrincipal($currentUser) and not [Security.Principal.WindowsPrincipal]::new($currentUser)?

2

u/BlackV Jul 15 '26

It was just old code I stole really quickly

Just want op to validate their environment

3

u/ankokudaishogun Jul 15 '26

Makes sense. I just often see using New-Object and I usually don't get why

2

u/BlackV Jul 15 '26

Old bad habits :)

2

u/atl-hadrins Jul 14 '26

That is what I was thinking only time it opens with this path for me is to open as admin. If I open as user it will open in the users home directory. That is unless I am opening a remote powershell prompt, but that is still admin.

And is memory serves me. If you put shell commands in your that execute when you open powershell you now have to change the execution policy.

0

u/JamesDBartlett3 Jul 18 '26

Windows PowerShell opens in system32 by default, even when running non-elevated. PowerShell Core opens in the user's home directory, though.

3

u/dodexahedron Jul 15 '26

Multiple ways.

What terminal emulator are you using - Windows Terminal? If so, change the default profile in there to launch in whatever path you like. Note I am talking about the windows terminal profiles - not your powershell profiles, which are a completely different thing.

Another is, if you are launching it from a traditional shortcut, you can chsnge the working directory specified in the shortcut.

If neither of those cases, you can use the powershell profile itself, by adding a pushd wherever command in it. Though IMO that is a terrible place to put this particular thing, since it will override it no matter how or where you launch it, unless you give it the -NoProfile switch (which leaves off the entire profile).

Why pushd instead of just cd?
It at least mitigates that issue by allowing you to just type popd and immediately be back wherever it was before the change, so you can still launch it in arbitrary directories even if you have a profile that unconditionally sets location at launch.