Skip to content

install-aishell Setting $env:Path And Removing Registry Expansion #406

@mattcargile

Description

@mattcargile

Prerequisites

  • Write a descriptive title.
  • Make sure you are able to repro it on the latest version
  • Search the existing issues.

Steps to reproduce

Install with aka.ms/install-aishell.ps1.

The script uses the SetEnvironmentVariable method which alters Path's registry key type.

$envPath = $env:Path
if (-not $envPath.Contains($destination)) {
Write-Host "Adding AI Shell app to the Path environment variable ..."
$env:Path = "${destination};${envPath}"
$userPath = [Environment]::GetEnvironmentVariable('Path', [EnvironmentVariableTarget]::User)
$newUserPath = $userPath.EndsWith(';') ? "${userPath}${destination}" : "${userPath};${destination}"
[Environment]::SetEnvironmentVariable('Path', $newUserPath, [EnvironmentVariableTarget]::User)
}

See the issue here.
Consider the below method instead.

$key = Get-Item 'HKCU:\Environment\'
# Will get the non-expanded values
$existingPath = $key.GetValue('PATH', '', 'DoNotExpandEnvironmentNames')
$newPath = "${existingPath};%TEST_VAR%"
$key.SetValue('PATH', $newPath, 'ExpandString')

Expected behavior

`$env:Path` maintains itself as an expand registry key.

Actual behavior

`$env:Path` is converted from the registry expand type.

Error details

No Error

Environment data

7.5.2

Version

Latest

Visuals

N/A

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions