private/Test-CommandCurl.ps1

function Test-CommandCurl {
    <#
    .SYNOPSIS
        Tests whether curl.exe is available and reports a valid version
 
    .DESCRIPTION
        Locates curl.exe as an application in the current session PATH, runs
        curl.exe --version, and parses the version from the first output line.
        Returns $true when curl.exe exits successfully and reports a version
        greater than 0.0. Returns $false when the command is unavailable, the
        command fails, or its version output cannot be parsed.
 
    .EXAMPLE
        PS> Test-CommandCurl
 
        Tests whether a working curl.exe command is available in the current
        session PATH.
 
    .INPUTS
        None. This function does not accept pipeline input.
 
    .OUTPUTS
        System.Boolean. Returns $true when curl.exe reports a valid version
        greater than 0.0; otherwise, returns $false.
 
    .NOTES
        Author: David Segura
        Company: Recast Software
        Version: 1.0.0
        Date: 2026-08-28
 
        The explicit .exe suffix prevents the PowerShell curl alias from being
        treated as the native executable.
 
    .LINK
        https://curl.se/docs/manpage.html
    #>

    [OutputType([bool])]
    param ()

    $curlCommand = Get-Command -Name 'curl.exe' -CommandType Application -ErrorAction SilentlyContinue |
        Select-Object -First 1

    if ($null -eq $curlCommand) {
        return $false
    }

    try {
        $versionOutput = @(& $curlCommand.Path --version 2>$null)
        if ($LASTEXITCODE -ne 0 -or $versionOutput.Count -eq 0) {
            return $false
        }

        if ([string]$versionOutput[0] -notmatch '^curl\s+(?<Version>\d+(?:\.\d+){1,3})\b') {
            return $false
        }

        $curlVersion = $null
        if (-not [System.Version]::TryParse($Matches.Version, [ref]$curlVersion)) {
            return $false
        }

        return ($curlVersion -gt [System.Version]'0.0')
    }
    catch {
        return $false
    }
}