29

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

Dustin Hammond
  • 291
  • 1
  • 3
  • 3
  • 1
    what do you get if you enter the command `notepad $profile` ? – Elroy Flynn Jan 25 '12 at 03:01
  • adding terms to hopefully improve search: $profile variable empty, does not exist, non-existent file – NH. Sep 22 '17 at 19:09
  • 2
    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'. – Kevin Nov 18 '20 at 12:09

3 Answers3

44

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.

mklement0
  • 382,024
  • 64
  • 607
  • 775
manojlds
  • 290,304
  • 63
  • 469
  • 417
4

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. :)

7absec
  • 41
  • 4
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
Biskrem Muhammad
  • 4,074
  • 3
  • 31
  • 38