PowerShell 101: Open in same folder every time
PowerShell (Profile) Tuesday, 04 August 2020 by paul

You can use a PowerShell profile to open the window to the same folder every time.

  1. Check if a profile already exists with command "Test-Path $profile"
  2. If it is false then create the profile file with the command "New-Item -path $profile -type file –force"
  3. Edit the file (usually created by default as filename c:\Users\username\Documents\WindowsPowerShell\Microsoft.Powershell_profile.ps1)
  4. Add the text "cd c:\foldername" and save changes

Or add more of a startup script:

$Shell = $Host.UI.RawUI
$Shell.WindowTitle="Windows PowerShell for Me"
Write-Host "Username:"$($env:username) -foreground gray
Write-Host "Hostname:"$($env:computername) -foreground gray
Write-Host "PS Version:"$Host.Version.ToString() -foreground gray
Write-Host ""
cd "$($env:onedrive)\Scripts"

Now when you start a PowerShell session it will always execute the profile file automatically and change you to the specified folder. You can also add commands to configure the size, location, title, prompts, create aliases and set colours of your PowerShell window.

Add Comment
No Comments.