#Requires -Version 7.4

function Get-vSEALFileVersion {
    <#
    .SYNOPSIS
        Gets the version of a file.

    .DESCRIPTION
        Retrieves the FileVersion or ProductVersion from a file's version info
        resource. The file must exist and contain version information.

    .PARAMETER File
        The file to get version information from. Must exist and have version
        information embedded (FileVersion or ProductVersion).

    .PARAMETER ProductVersion
        Return ProductVersion instead of FileVersion.

    .OUTPUTS
        [string] The file or product version.
    #>
    [CmdletBinding()]
    [OutputType([string])]
    param(
        [Parameter(Mandatory)]
        [ValidateScript({
            if (-not $_.Exists) {
                throw "File does not exist: $_"
            }
            if (-not $_.VersionInfo -or (-not $_.VersionInfo.FileVersion -and -not $_.VersionInfo.ProductVersion)) {
                throw "File has no version information: $_"
            }
            $true
        })]
        [System.IO.FileInfo]$File,

        [switch]$ProductVersion
    )

    if ($ProductVersion) {
        Write-vSEALLog "Product version of [$File]: $($File.VersionInfo.ProductVersion)" -Level VERBOSE
        return $File.VersionInfo.ProductVersion.Trim()
    }

    Write-vSEALLog "File version of [$File]: $($File.VersionInfo.FileVersion)" -Level VERBOSE
    return $File.VersionInfo.FileVersion.Trim()
}
