Search code examples
powershellpowershell-core

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?


Solution

  • 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"