From a4eaf8f294547fd7a50e30e3f6abfc442ed29504 Mon Sep 17 00:00:00 2001 From: caomengxuan666 <2507560089@qq.com> Date: Thu, 4 Jun 2026 19:34:26 +0800 Subject: [PATCH 1/3] Accept InstallLocation for PowerShell installs --- src/pwsh-install.ps1 | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/pwsh-install.ps1 b/src/pwsh-install.ps1 index 86935fc..506a5e2 100644 --- a/src/pwsh-install.ps1 +++ b/src/pwsh-install.ps1 @@ -105,7 +105,15 @@ function Update-PowerShellProfile([string]$Path, [bool] $Install, [bool] $UseBom function Get-MsiPwshInstalls { Get-ChildItem -LiteralPath 'HKLM:\SOFTWARE\Microsoft\PowerShellCore\InstalledVersions' -ErrorAction Ignore | ForEach-Object { $props = Get-ItemProperty -LiteralPath $_.PSPath -ErrorAction Ignore - if (!($props -and $props.InstallDir -and $props.SemanticVersion)) { + if (!($props -and $props.SemanticVersion)) { + return + } + + $installDir = $props.InstallDir + if (!$installDir) { + $installDir = $props.InstallLocation + } + if (!$installDir) { return } @@ -121,8 +129,8 @@ function Get-MsiPwshInstalls { } [PSCustomObject]@{ - InstallDir = $props.InstallDir - ProfilePath = Join-Path $props.InstallDir 'Microsoft.PowerShell_profile.ps1' + InstallDir = $installDir + ProfilePath = Join-Path $installDir 'Microsoft.PowerShell_profile.ps1' } } } From 78ff1fa583fbb9dba9ff59e7a79b0d89caed72e0 Mon Sep 17 00:00:00 2001 From: Leonard Hecker Date: Thu, 4 Jun 2026 14:55:40 +0200 Subject: [PATCH 2/3] Fix property access guards --- src/pwsh-install.ps1 | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/src/pwsh-install.ps1 b/src/pwsh-install.ps1 index 506a5e2..e1bddf9 100644 --- a/src/pwsh-install.ps1 +++ b/src/pwsh-install.ps1 @@ -105,15 +105,7 @@ function Update-PowerShellProfile([string]$Path, [bool] $Install, [bool] $UseBom function Get-MsiPwshInstalls { Get-ChildItem -LiteralPath 'HKLM:\SOFTWARE\Microsoft\PowerShellCore\InstalledVersions' -ErrorAction Ignore | ForEach-Object { $props = Get-ItemProperty -LiteralPath $_.PSPath -ErrorAction Ignore - if (!($props -and $props.SemanticVersion)) { - return - } - - $installDir = $props.InstallDir - if (!$installDir) { - $installDir = $props.InstallLocation - } - if (!$installDir) { + if (!$props -or !$props.PSObject.Properties['InstallLocation'] -or !$props.PSObject.Properties['SemanticVersion']) { return } @@ -129,8 +121,8 @@ function Get-MsiPwshInstalls { } [PSCustomObject]@{ - InstallDir = $installDir - ProfilePath = Join-Path $installDir 'Microsoft.PowerShell_profile.ps1' + InstallLocation = $props.InstallLocation + ProfilePath = Join-Path $props.InstallLocation 'Microsoft.PowerShell_profile.ps1' } } } From d9918b46c21f1efc058d10dba1beabb085418a68 Mon Sep 17 00:00:00 2001 From: Leonard Hecker Date: Thu, 4 Jun 2026 14:58:55 +0200 Subject: [PATCH 3/3] Simplify invocation --- src/pwsh-install.ps1 | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/pwsh-install.ps1 b/src/pwsh-install.ps1 index e1bddf9..7bc34d5 100644 --- a/src/pwsh-install.ps1 +++ b/src/pwsh-install.ps1 @@ -102,7 +102,7 @@ function Update-PowerShellProfile([string]$Path, [bool] $Install, [bool] $UseBom } } -function Get-MsiPwshInstalls { +function Get-MsiPwshProfilePaths { Get-ChildItem -LiteralPath 'HKLM:\SOFTWARE\Microsoft\PowerShellCore\InstalledVersions' -ErrorAction Ignore | ForEach-Object { $props = Get-ItemProperty -LiteralPath $_.PSPath -ErrorAction Ignore if (!$props -or !$props.PSObject.Properties['InstallLocation'] -or !$props.PSObject.Properties['SemanticVersion']) { @@ -120,10 +120,7 @@ function Get-MsiPwshInstalls { return } - [PSCustomObject]@{ - InstallLocation = $props.InstallLocation - ProfilePath = Join-Path $props.InstallLocation 'Microsoft.PowerShell_profile.ps1' - } + Join-Path $props.InstallLocation 'Microsoft.PowerShell_profile.ps1' } } @@ -210,8 +207,8 @@ function Get-ProfilePlan([bool] $Install, [string]$Scope) { return $obj } - foreach ($i in Get-MsiPwshInstalls) { - $entry = Add $i.ProfilePath + foreach ($profilePath in Get-MsiPwshProfilePaths) { + $entry = Add $profilePath if ($allUsersInstall) { $entry.Install = $true }