Learning and Sharing
  • Home
  • Blog
  • Linux
  • macOS
  • Virtualization
    • VMware
    • VirtualBox
  • Windows
    • Windows 11
    • Windows 10
    • Windows Server
  • Series
    • Symantec
    • Intune
    • Microsoft Azure
    • Powershell
    • VirtualBox
    • VMware
    • PowerShell Learning
    • Microsoft Graph
  • More
    • Auto Installation
    • AEC Installation
  • Contact
No Result
View All Result
  • Home
  • Blog
  • Linux
  • macOS
  • Virtualization
    • VMware
    • VirtualBox
  • Windows
    • Windows 11
    • Windows 10
    • Windows Server
  • Series
    • Symantec
    • Intune
    • Microsoft Azure
    • Powershell
    • VirtualBox
    • VMware
    • PowerShell Learning
    • Microsoft Graph
  • More
    • Auto Installation
    • AEC Installation
  • Contact
No Result
View All Result
No Result
View All Result

How to Configure or Change the PowerShell Default Working Directory

August 28, 2023
in Blog, Powershell
0
ADVERTISEMENT

Table of Contents

Change the PowerShell Default Working Directory

In some cases, you want to start PowerShell in your favorite working directory such as D:\scripts for daily at work. So, you don’t need to navigate to it every time you open PowerShell.

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%
JNQN7UVVn2tGQq9F1bfJMuPsoCRZxKLvt1JNeiwqtmXAeGWLT8Tv0Z9dH6cF

If you open an elevated PowerShell window, it started in C:\Windows\System32.

RGjFAVGGLuiRTvFEf4Mv8P8C0DKOCCGTTBKBaz8RZJraBqelTJYQnIbenx4X

There are several ways to change this:

  • Set a shortcut and change the Start in path in the properties.
  • Create a PowerShell profile.

Method 1: Using PowerShell

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.

1️⃣ Run PowerShell as administrator and execute the following command. 

Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Force

This will permit PowerShell to run local scripts and scripts downloaded from the Internet that have been signed. Read more about this command in the documentation.

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

New-Item -Path $profile -Type File -Force
PS C:\Windows\system32> New-Item -Path $profile -Type File -Force

    Directory: C:\Users\admin\Documents\WindowsPowerShell

Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
-a----         8/21/2023   8:48 AM              0 Microsoft.PowerShell_profile.ps1

From now on there is a new PowerShell script in the following path. The file Microsoft.PowerShell_profile.ps1 would be loaded every time you open PowerShell.

PS C:\Windows\system32> $profile

C:\Users\admin\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1

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

notepad $profile

For example, we’ll change the default working directory to D:\scripts.

OQHOAn7Z8QVBtTzqlI3pOC3sHECaG3A7pbXYNfP5y3zWtpp4T9JCGFsHqxyU

4️⃣ Close then reopen a new PowerShell window, the working directory should be changed as expected.

0RCnIhMjF2AS0K8I9Af0amCWzU3dxy9TKJ5b3haziKf5XUlpDhTBpezeH9Gm

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

PS C:\Windows\system32> $PROFILE | fl -force

AllUsersAllHosts       : C:\Windows\System32\WindowsPowerShell\v1.0\profile.ps1
AllUsersCurrentHost    : C:\Windows\System32\WindowsPowerShell\v1.0\Microsoft.PowerShell_profile.ps1
CurrentUserAllHosts    : C:\Users\admin\Documents\WindowsPowerShell\profile.ps1
CurrentUserCurrentHost : C:\Users\admin\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1
Length                 : 75

To check if a profile exists you can use:

PS C:\Windows\system32> Test-Path $PROFILE.CurrentUserCurrentHost
True
PS C:\Windows\system32> Test-Path $PROFILE.AllUsersAllHosts
False

Bonus: If you’re a PowerShell nerd like us, you may like the below script to do all above tasks:

Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Force
New-Item -Path $profile -Type File -Force
Add-Content $profile 'Set-Location C:\'

Method 2: Change the Start folder

The second way, you can change the Start in property of the PowerShell shortcut to change the default working directory as follows:

1️⃣ Search PowerShell then right click on it and select Open file location.

zrZqTlr6VhlW7ioNdLZVnBUTsDJ5uWzFCzSkYJzibwRBBE9qnR9UQWd84o6G

2️⃣ Right click on each shortcut then change the Start in property.

Cv5LyRNo2tTS7DnuQuYuuqYY2GKuFakbYgcFRfaYGe6dMVUGCOSCebk4Apmg

3️⃣ To set and change the default working directory, change with your desired path.

aMQsfHckIN2PiwiJClmHKjHjet6NvgpmNYOJFStnVEEgrfGijbLPd1ZHRynZ

Not a reader? Watch this related video tutorial:

5/5 - (1 vote)
Previous Post

How to Fix the Term Select-MgProfile is not Recognized Error

Next Post

How to Upgrade to Microsoft Graph PowerShell SDK v2

Related Posts

Running Hyper-V and VMware Workstation on The Same Machine

August 15, 2024

How to Uninstall All Autodesk Products At Once Silently

July 29, 2024
Ftr5

How to Uninstall the Autodesk Genuine Service on Windows

July 29, 2024
Ftr19

How to Fix Windows Cannot Read the ProductKey From the Unattend Answer File in VirtualBox

July 26, 2024
Ftr25

How to Update Windows Terminal in Windows 10/11

July 26, 2024

How to Disable The Beep Sound in WSL Terminal on Windows

July 26, 2024

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Recent Posts

  • How To Turn On uBlock Origin Extension in Chrome (2025)
  • Images Hidden Due To Mature Content Settings In CivitAI
  • Azure OpenAI vs Azure AI Hub, How to Choose the Right One for Your Needs

Categories

Stay in Touch

Discord Server

Join the Discord server with the site members for all questions and discussions.

Telegram Community

Jump in Telegram server. Ask questions and discuss everything with the site members.

Youtube Channel

Watch more videos, learning and sharing with Leo ❤❤❤. Sharing to be better.

Newsletter

Join the movement and receive our weekly Tech related newsletter. It’s Free.

General

Microsoft Windows

Microsoft Office

VMware

VirtualBox

Technology

PowerShell

Microsoft 365

Microsoft Teams

Email Servers

Copyright 2025 © All rights Reserved. Design by Leo with ❤

No Result
View All Result
  • Home
  • Linux
  • Intune
  • macOS
  • VMware
  • VirtualBox
  • Powershell
  • Windows 10
  • Windows 11
  • Microsoft 365
  • Microsoft Azure
  • Microsoft Office
  • Active Directory

No Result
View All Result
  • Home
  • Linux
  • Intune
  • macOS
  • VMware
  • VirtualBox
  • Powershell
  • Windows 10
  • Windows 11
  • Microsoft 365
  • Microsoft Azure
  • Microsoft Office
  • Active Directory