Powershell: $profile is pointing to a path that I can't find and setting permanent path
Asked Answered
L

3

30

I am looking at my $profile variable and I see that it is pointing to C:\users\username\Documents\windowsPowershell\Microsoft.Powershell_profile.ps1

However, when I attempt to browse to this directory I cannot find the folder/directory named WindowsPowerShell that is supposed to be in the documents folder. Any ideas?

I was hoping I could set a permanent path that is linked to my profile or at least loaded with it when Powershell is loaded. Am I on the right track here?

thanks!

-Dustin

Letreece answered 25/1, 2012 at 2:53 Comment(3)
what do you get if you enter the command notepad $profile ?Archaean
adding terms to hopefully improve search: $profile variable empty, does not exist, non-existent fileGeneva
Yo bro, I'm getting that same exact error. It's like windowsPowershell is a directory that does not actually exist. When I 'notepad $profile' an error pops up saying 'The system cannot find the path specified'.Opalina
V
48

What you see for the path is right. It is the path for your user profile (for the console host) and it is normal to not see the folder and the file. You can create it and start using your profile:

new-item -type file -path $profile -force

See here for more: about_Profiles.

Vashti answered 25/1, 2012 at 3:5 Comment(0)
V
6

This is the case when you mistakenly delete your profile file.

You can manually create the "Microsoft.Powershell_profile.ps1" at the location of your profile.

  1. execute $profile in cmd/powershell and you will get the location of your profile.
  2. Create the subsequent folders and the file.

In my case, it was "D:\OneDrive\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1"

  1. So, I manually create the "WindowsPowerShell" folder inside Documents and the "Microsoft.PowerShell_profile.ps1" file in WindowsPowerShell.

  2. Then pasted the content in the profile.

    Import-Module posh-git

    Import-Module oh-my-posh

    Set-PoshPrompt -Theme Paradox

Hope this resolves your issue. :)

Vociferant answered 17/12, 2021 at 3:25 Comment(0)
T
1

You can edit it by running in the terminal code $PROFILE if you have visual studio code installed. this will open the file and then you can edit it.

now add your commands to be ran whenever opening a new terminal window, like to use "Oh My Posh"

if you have it already installed Install-Module oh-my-posh -Scope CurrentUser

add these lines to your profile file to load your preferred theme when a new terminal window opened.

Import-Module oh-my-posh
Set-PoshPrompt -Theme Aliens
Tasia answered 30/4, 2021 at 20:33 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.