Many PowerShell users encounter an unexpected situation where their $PROFILE path incorrectly points to a network share location (e.g., H:\WindowsPowerShell\) despite having a local %USERPROFILE% (e.g., C:\Users\username). This creates security warnings and performance issues when loading the profile script.
# Current problematic output:
PS> $PROFILE
H:\WindowsPowerShell\Microsoft.PowerShell_profile.ps1
PS> $env:USERPROFILE
C:\Users\username
PowerShell determines the $PROFILE path using the following precedence:
- %HOMEDRIVE%%HOMEPATH% (network share in your case)
- %USERPROFILE% (local profile)
- Default documents location
Here are three methods to change the profile location:
Method 1: Registry Modification (Permanent Solution)
Change the system's home directory pointers in the registry:
# Run in elevated PowerShell:
Set-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList\$(New-Object System.Security.Principal.SecurityIdentifier (Get-ItemProperty 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList\*' | Where-Object { $_.ProfileImagePath -like "*$env:USERNAME*" } | Select-Object -First 1).PSChildName)" -Name "ProfileImagePath" -Value $env:USERPROFILE
# Then modify user environment variables:
[Environment]::SetEnvironmentVariable("HOMEDRIVE", "C:", "User")
[Environment]::SetEnvironmentVariable("HOMEPATH", "\Users\$env:USERNAME", "User")
Method 2: Profile Redirection (Immediate Workaround)
Create a custom profile loader in the default location that points to your preferred location:
# Content of Microsoft.PowerShell_profile.ps1 in default location:
$CustomProfilePath = "C:\Users\$env:USERNAME\Documents\PowerShell\CustomProfile.ps1"
if (Test-Path $CustomProfilePath) {
. $CustomProfilePath
}
Method 3: PowerShell Configuration File
Edit PowerShell's configuration file to override profile paths:
# Create or modify $PSHOME\powershell.config.json
@"
{
"Microsoft.PowerShell:ExecutionPolicy": "RemoteSigned",
"PowerShellPolicies": {
"ScriptExecution": {
"ExecutionPolicy": "RemoteSigned",
"ScriptsToProcess": [
"C:/Users/$env:USERNAME/Documents/PowerShell/Profile.ps1"
]
}
}
}
"@ | Set-Content "$PSHOME\powershell.config.json"
After implementing any solution, verify with:
# Check new profile path
$PROFILE
# Test profile loading
. $PROFILE
- Network latency when loading from H: drive
- Group Policy restrictions on script execution
- Multiple PowerShell hosts (ISE, VS Code) may have different profile paths
Many PowerShell users encounter a situation where their $profile
variable unexpectedly points to a network share location (like H:\) instead of the local user profile directory. This happens despite Microsoft's documentation suggesting the path should follow %USERPROFILE%
.
In reality, PowerShell determines the $profile
location using this priority:
- The
HOME
environment variable (if set) - The combination of
HOMEDRIVE
andHOMEPATH
- Finally falling back to
USERPROFILE
To permanently change where PowerShell looks for your profile:
# Set the HOME variable to your preferred location
[Environment]::SetEnvironmentVariable("HOME", "$env:USERPROFILE", "User")
# Verify the change
$env:HOME = [Environment]::GetEnvironmentVariable("HOME", "User")
$profile
For a session-specific solution, you can manually set the profile path:
$profile = "$env:USERPROFILE\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1"
. $profile # Dot-source to load the profile
After changing the path, create your profile:
if (!(Test-Path -Path $profile)) {
New-Item -ItemType File -Path $profile -Force
Add-Content -Path $profile -Value "# My PowerShell Profile"
}
PowerShell actually supports multiple profile paths. You can check all possible locations:
$PROFILE | Format-List -Force
# Sample output:
# AllUsersAllHosts : C:\Windows\System32\WindowsPowerShell\v1.0\profile.ps1
# AllUsersCurrentHost : C:\Windows\System32\WindowsPowerShell\v1.0\Microsoft.PowerShell_profile.ps1
# CurrentUserAllHosts : C:\Users\username\Documents\WindowsPowerShell\profile.ps1
# CurrentUserCurrentHost : C:\Users\username\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1
When storing your profile on network shares:
- Sign your profile script with a code-signing certificate
- Consider setting the execution policy to RemoteSigned
- Add network share paths to PowerShell's trusted locations
Set-ExecutionPolicy RemoteSigned -Scope CurrentUser
For maximum flexibility, create a loader profile that sources your actual profile:
# Content of the default profile location
$actualProfilePath = "$env:USERPROFILE\Documents\PowerShell\MyActualProfile.ps1"
if (Test-Path $actualProfilePath) {
. $actualProfilePath
} else {
Write-Warning "Profile not found at $actualProfilePath"
}
If issues persist:
- Check all environment variables:
dir env: | Where-Object Name -like "*HOME*"
- Verify group policies that might affect profile locations
- Check for profile scripts in all possible locations