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.
Answer from manojlds on Stack OverflowWhat 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.
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.
- execute
$profilein cmd/powershell and you will get the location of your profile. - Create the subsequent folders and the file.
In my case, it was
"D:\OneDrive\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1"
So, I manually create the "
WindowsPowerShell" folder insideDocumentsand the "Microsoft.PowerShell_profile.ps1" file inWindowsPowerShell.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. :)
powershell profile location
Is it possible to change the $PROFILE path?
Powershell $PROFILE variable pointing to wrong location. Where is $PROFILE variable it set? - Stack Overflow
$PROFILE suddenly pointing to wrong location
Videos
As @FrankMerrow posted, on this Stack Overflow question you will find the answer, but the correct is the one from Neck Beard, I'll copy it here.
As @woter324 points out issuing $profile | select * will show you the paths from where PowerShell gets profiles. As stated in the MS documentation:
The profiles are listed in precedence order. The first profile has the highest precedence.
<username>
profile | select *
AllUsersAllHosts : C:\Windows\System32\WindowsPowerShell\v1.0\profile.ps1
AllUsersCurrentHost : C:\Windows\System32\WindowsPowerShell\v1.0\Microsoft.PowerShell_profile.ps1
CurrentUserAllHosts : C:\Users\<username>\Documentos\WindowsPowerShell\profile.ps1
CurrentUserCurrentHost : C:\Users\<username>\Documentos\WindowsPowerShell\Microsoft.PowerShell_profile.ps1
Length : <will vary>
Those above are mine's, I supose you get something like
CurrentUserAllHosts : H:\WindowsPowerShell\profile.ps1
CurrentUserCurrentHost : H:\WindowsPowerShell\Microsoft.PowerShell_profile.ps1
In order to edit those paths you have two ways
Via regedit
Edit the key with name Personal that you will find under HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders
Via PowerShell
I didn't test this one, in the linked thread a user says it has to be tweaked in order to work but I supose it should be easy to get through.
Issue
New-ItemProperty
'HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders'
Personal -Value 'Your New Path Here' -Type ExpandString -Force
Either way you have to reboot Power Shell (or windoes terminal) for this to take effect. You can then check again with $profile | select *.
You might also check out this post on Stack Overflow. The best solution offered so far (to my almost identical question) is to change $profile.AllUsersAllHosts to "dot source" another file of your own choosing.
I've seen nothing so far to indicate you can change the default value of $profile itself.
The answer from harrymc is mostly right, except Microsoft has changed things and moves things around and doesn't update their documentation.
Try this to understand your Powershell "profile" scripts:
PS C:\Users\you> $PROFILE | select-object *
The output will be something like:
AllUsersAllHosts : C:\Program Files\PowerShell\7\profile.ps1
AllUsersCurrentHost : C:\Program Files\PowerShell\7\Microsoft.PowerShell_profile.ps1
CurrentUserAllHosts : C:\Users\you\OneDrive\Documents\PowerShell\profile.ps1
CurrentUserCurrentHost : C:\Users\you\OneDrive\Documents\PowerShell\Microsoft.PowerShell_profile.ps1
Length : 77
This tells you where the profiles are, for you.
The blog post you have found is from 2012 and refers to an older version of Windows. While most of it is still correct, the profile folders are not up to date.
The article you found is more recent from 2023, so is to be
taken seriously.
The "Current user, Current Host" profile location is said to
be in $HOME\Documents\PowerShell, which refers to
C:\Users\USER-NAME\Documents\PowerShell.
If you install OneDrive, it will by default backup the
Documents folder, by relocating it into the OneDrive
sync folder and leaving only a pointer to it in
C:\Users\USER-NAME.
This means that, if you have accepted the default setup of OneDrive, your PowerShell profiles are by default synced to OneDrive, but your reference is to a local folder. The profiles will be backed up to OneDrive, but the reference should stay to the local disk, not to the OneDrive folder in the cloud, to avoid problems when there is no internet connection.
$PROFILE returns C:\Users\jane\Documents\PowerShell\Microsoft.PowerShell_profile.ps1 as the default location.
Can I change it to C:\Users\jane\.config\pwsh\profile.ps1 ?
Kind of a powershell noob, i tried multiple AI chatbots and google, didn't get a satisfied solution. I want to move every local config file to .config , so far everything done except for powershell.
I came across this while searching for an answer - the profile will be found under a new directory:
$env:UserProfile\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1
To change where PowerShell looks for the default profile, you need to change a Registry key:
- Open Registry Editor and navigate to:
HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders - Change value of
Personalto the directory of your choice
Automated way with PowerShell:
-
Set-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name "Personal" -Value "DRIVEHERE"` - Test the value:
Get-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name "Personal"
Solved: When I enabled Documents backup to OneDrive and relogged in $PROFILE was back to the correct location:
It turns out before the problem occurred, $PROFILE had pointed to the OneDrive Documents folder:
$env:UserProfile\OneDrive\Documents\PowerShell\Microsoft.PowerShell_profile.ps1
I am unsure, but it seems if PowerShell doesn't find the profile location under Documents or $HOME, it defaults to C:\PowerShell (it would be nice to have clear specification on this behaviour).