Change the Powershell $profile directory

Posted by Swoogan on Server Fault See other posts from Server Fault or by Swoogan
Published on 2010-10-27T16:46:10Z Indexed on 2010/12/25 2:55 UTC
Read the original article Hit count: 301

Filed under:
|
|

I would like to know how to change my the location my $profile variable points to.

PS H:\> $profile
H:\WindowsPowerShell\Microsoft.PowerShell_profile.ps1

H:\ is a network share, so when I create my profile file, and load powershell I get the following:

Security Warning Run only scripts that you trust. While scripts from the Internet can be useful, this script can potentially harm your computer. Do you want to run H:\WindowsPowerShell\Microsoft.PowerShell_profile.ps1? [D] Do not run [R] Run once [S] Suspend [?] Help (default is "D"):

According to Microsoft, the location of the $profile is determined by the %USERPROFILE% environment variable. This is not true:

PS H:\> $env:userprofile
C:\Users\username

For example, I have an XP machine working how I want:

PS H:\> $profile
C:\Documents and Settings\username\My Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1
PS H:\> $env:userprofile
C:\Documents and Settings\username
PS H:\> $env:homedrive
H:
PS H:\> $env:homepath
\

Here's the same output from the Vista machine where the $profile points to the wrong place:

PS H:\> $profile
H:\WindowsPowerShell\Microsoft.PowerShell_profile.ps1
PS H:\> $env:userprofile
C:\Users\username
PS H:\> $env:homedrive
H:
PS H:\> $env:homepath
\

Since $profile isn't actually determined by %USERPROFILE% how do I change it? Clearly anything that involves changing the homedrive or homepath is not the solution I'm looking for.

© Server Fault or respective owner

Related posts about Windows

Related posts about powershell