private/Test-InstallPwsh.ps1
|
function Test-InstallPwsh { <# .SYNOPSIS Tests whether PowerShell 7 is installed .DESCRIPTION Checks for PowerShell\7\pwsh.exe under ProgramFiles. If the file does not exist, searches the 64-bit and 32-bit machine uninstall registry for a display name beginning with PowerShell 7. Returns $true when either method finds an installation; otherwise, returns $false. .EXAMPLE PS> Test-InstallPwsh Tests the default path and uninstall registry for PowerShell 7. .INPUTS None. This function does not accept pipeline input. .OUTPUTS System.Boolean. Returns $true when PowerShell 7 is detected; otherwise, returns $false. .NOTES Author: David Segura Company: Recast Software Version: 1.0.0 Date: 2026-08-28 .LINK Test-CommandPwsh #> [OutputType([bool])] param () # Fast path — default install location if (Test-Path -Path (Join-Path $env:ProgramFiles 'PowerShell\7\pwsh.exe')) { return $true } # Registry fallback $regPaths = @( 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\*', 'HKLM:\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*' ) foreach ($regPath in $regPaths) { $entry = Get-ItemProperty -Path $regPath -ErrorAction SilentlyContinue | Where-Object { $_.PSObject.Properties['DisplayName'] -and $_.DisplayName -like 'PowerShell 7*' } | Select-Object -First 1 if ($entry) { return $true } } return $false } |