Welcome Forums General PowerShell Q&A New-PSSession and Path consistency

Viewing 1 reply thread
  • Author
    Posts
    • #80630
      Participant
      Topics: 1
      Replies: 0
      Points: 0
      Rank: Member

      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
      
    • #80654
      Participant
      Topics: 2
      Replies: 376
      Points: 1
      Rank: Member
      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.

Viewing 1 reply thread
  • The topic ‘New-PSSession and Path consistency’ is closed to new replies.