Quantcast
Channel: PowerShell.org » All Posts
Viewing all articles
Browse latest Browse all 13067

Reply To: Where are the default powershell environment variables physically stored?

$
0
0

There are a few different concepts in play here:

Environment Variables, such as PSModulePath, have a few different "scopes" (for lack of a better term). There are System environment variables that apply to all users, User environment variables that apply to all processes for a particular user, and Process environment variables which are set at runtime, but not saved. When you start a new process, you inherit values from all three sets (including Process variables from whatever parent process launched the new one.)

$profile is a variable which contains several paths to scripts that PowerShell will execute on startup if they exist, but the folders and scripts themselves do not exist by default. If you want a profile, you have to create it. For example, this bit of code will create a profile.ps1 script (which executes for both PowerShell.exe and the ISE) for the current user, if it doesn't already exist, then opens that profile script in the ISE:

$profilePath = $profile.CurrentUserAllHosts
$profileFolder = Split-Path $profilePath -Parent
 
if (-not (Test-Path $profileFolder -PathType Container))
{
    $null = mkdir $profileFolder
}
 
if (-not (Test-Path $profilePath -PathType Leaf))
{
    $null = New-Item $profilePath -ItemType File
}
 
ise $profilePath

Viewing all articles
Browse latest Browse all 13067

Trending Articles