Author Posts

September 26, 2017 at 6:18 pm

I'm trying to understand why $env:path is inconsistent when I enter a new PSSession.

Consider this very simple example:

PS E:\> $env:path
C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;E:\Oracle\Database\db11204\oracle_db1\bin
PS E:\> Enter-PSSession localhost
[localhost]: PS C:\Users\user1\Documents> $env:path
C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\

I've found that $env:path in the new session matches that in the ControlSet002, but why?

PS E:\> (Get-ItemProperty -Path 'HKLM:\\SYSTEM\CurrentControlSet\Control\Session Manager\Environment').Path
C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;E:\Oracle\Database\db11204\oracle_db1\bin
PS E:\> (Get-ItemProperty -Path 'HKLM:\\SYSTEM\ControlSet001\Control\Session Manager\Environment').Path
C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;E:\Oracle\Database\db11204\oracle_db1\bin
PS E:\> (Get-ItemProperty -Path 'HKLM:\\SYSTEM\ControlSet002\Control\Session Manager\Environment').Path
C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\

Any help is appreciated!

Brian

SYSTEM INFO:
----------------------
Windows Server 2012 R2

PS E:\> $host

Name             : ConsoleHost
Version          : 4.0
InstanceId       : ccb7c23b-889a-4912-9107-cb270b7b6e0c
UI               : System.Management.Automation.Internal.Host.InternalHostUserInterface
CurrentCulture   : en-US
CurrentUICulture : en-US
PrivateData      : Microsoft.PowerShell.ConsoleHost+ConsoleColorProxy
IsRunspacePushed : False
Runspace         : System.Management.Automation.Runspaces.LocalRunspace

September 27, 2017 at 7:00 am

0..2 | Foreach-Object {
  Write-Host ('Path for {0}' -f [System.EnvironmentVariableTarget]$_) -ForegroundColor Green
  [System.Environment]::GetEnvironmentVariable('path',$_) -split ';'
}

if you find a difference, for process this can be from powershell profile, for user – from user env and machine should be the same.