By default when you start a new PowerShell session, you will get directly to your user directory stored in the environment variables. By default it is located in C:Users<username>.

%HOMEDRIVE%%HOMEPATH%

There are several ways to change this, one is to set a shortcut and change the Start in path in the properties.

Another method which I prefer is to create a PowerShell profile in order to customize my environment which is applied to each PowerShell session I will start.

PowerShell profiles will not automatically created for the users, you have to create it yourself as follows.

New-Item -path $profile -type file –force


From now on there is a new PowerShell script in the following path.

%HOMEPATH%DocumentsWindowsPowerShellMicrosoft.PowerShell_profile.ps1


To set and change the default working directory, open the above script and add the following line with your desired path.

Set-location C:Temp


You can determine the path’s where the profiles must be located for the current user and all users with the following command

$PROFILE | fl -force

PS> $PROFILE | fl -Force

AllUsersAllHosts       : C:WindowsSystem32WindowsPowerShellv1.0profile.ps1
AllUsersCurrentHost    : C:WindowsSystem32WindowsPowerShellv1.0Microsoft.PowerShell_profile.ps1
CurrentUserAllHosts    : C:UsersuserDocumentsWindowsPowerShellprofile.ps1
CurrentUserCurrentHost : C:UsersuserDocumentsWindowsPowerShellMicrosoft.PowerShell_profile.ps1
Length                 : 75

PS> $PROFILE.AllUsersAllHosts
C:WindowsSystem32WindowsPowerShellv1.0profile.ps1


To check if a profile exists you can use

PS C:> Test-Path $PROFILE.CurrentUserCurrentHost
True

PS C:> Test-Path $PROFILE.AllUsersAllHosts
False





Links


About Profiles
https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_profiles?view=powershell-7.1