diff --git a/src/pwsh-install.ps1 b/src/pwsh-install.ps1 index 86935fc..7bc34d5 100644 --- a/src/pwsh-install.ps1 +++ b/src/pwsh-install.ps1 @@ -102,10 +102,10 @@ 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 -and $props.InstallDir -and $props.SemanticVersion)) { + if (!$props -or !$props.PSObject.Properties['InstallLocation'] -or !$props.PSObject.Properties['SemanticVersion']) { return } @@ -120,10 +120,7 @@ function Get-MsiPwshInstalls { return } - [PSCustomObject]@{ - InstallDir = $props.InstallDir - ProfilePath = Join-Path $props.InstallDir '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 }