private/Test-InstallGit.ps1
|
function Test-InstallGit { <# .SYNOPSIS Tests whether Git for Windows is installed .DESCRIPTION Checks for Git\cmd\git.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 Git. Returns $true when either method finds an installation; otherwise, returns $false. .EXAMPLE PS> Test-InstallGit Tests the default path and uninstall registry for Git for Windows. .INPUTS None. This function does not accept pipeline input. .OUTPUTS System.Boolean. Returns $true when Git for Windows is detected; otherwise, returns $false. .NOTES Author: David Segura Company: Recast Software Version: 1.0.0 Date: 2026-08-28 .LINK Test-CommandGit #> [OutputType([bool])] param () # Fast path — default install location if (Test-Path -Path (Join-Path $env:ProgramFiles 'Git\cmd\git.exe')) { return $true } $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 'Git*' } | Select-Object -First 1 if ($entry) { return $true } } return $false } |