Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Powershell $PROFILE variable pointing to wrong location. Where is $PROFILE variable it set?

After doing some changes to my machine, PowerShell fails because the $PROFILE variable points to a different location than before, causing problems like installed modules not found, etc:

  • It is set to:
    C:\PowerShell\Microsoft.PowerShell_profile.ps1
    
  • Instead of:
    $env:UserProfile\Documents\Powershell\Microsoft.PowerShell_profile.ps1
    

How does PowerShell set the value of $PROFILE, and can it be changed?

like image 934
arividar Avatar asked Oct 20 '25 15:10

arividar


1 Answers

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:

  1. Open Registry Editor and navigate to:
    HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders
    
  2. Change value of Personal to the directory of your choice

Automated way with PowerShell:

  1. Set-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name "Personal" -Value "DRIVEHERE"`
    
  2. Test the value:
    Get-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name "Personal"
    
like image 113
Questioning Avatar answered Oct 23 '25 07:10

Questioning