private/Test-CommandVSCode.ps1
|
function Test-CommandVSCode { <# .SYNOPSIS Tests whether the Visual Studio Code command is available .DESCRIPTION Uses command discovery to locate code in the current session PATH. If it is not found, checks the per-user and system-wide code.cmd paths. Returns $true when any of these checks succeeds; otherwise, returns $false. The function does not execute the command. .EXAMPLE PS> Test-CommandVSCode Tests whether the stable Visual Studio Code command is available. .INPUTS None. This function does not accept pipeline input. .OUTPUTS System.Boolean. Returns $true when code or a known code.cmd path is found; otherwise, returns $false. .NOTES Author: David Segura Company: Recast Software Version: 1.0.0 Date: 2026-08-28 The fallback checks use LOCALAPPDATA and ProgramFiles from the current environment. .LINK Test-InstallVSCode #> [OutputType([bool])] param () if (Get-Command -Name 'code' -ErrorAction SilentlyContinue) { return $true } $fallbackPaths = @( (Join-Path $env:LOCALAPPDATA 'Programs\Microsoft VS Code\bin\code.cmd'), (Join-Path $env:ProgramFiles 'Microsoft VS Code\bin\code.cmd') ) foreach ($path in $fallbackPaths) { if (Test-Path -Path $path) { return $true } } return $false } |