Public/Compare-SpecLocalFileHashToRemoteHash.ps1

Function Compare-SpecLocalFileHashToRemoteHash {
    [cmdletbinding()]

    param (
        [parameter (Mandatory = $true)]
        [string]$LocalFilePath,

        [parameter (Mandatory = $true)]
        [string]$RemoteFileHash
    )

    # get the file name from the local file path
    $fileName = Split-Path $LocalFilePath -Leaf

    #1. Get the remote file hash
    if (Test-Path $LocalFilePath) {
        write-host "Local file [$LocalFilePath] exists - getting hash" -ForegroundColor DarkGray
        $LocalHash = Get-SpecMDFileHashBase64 -FilePath $LocalFilePath
        write-host "Local hash is '$LocalHash'" -ForegroundColor DarkGray
    } else {
        write-host "Local file [$LocalFilePath] does not exist - skipping hash check" -ForegroundColor DarkGray
        $LocalHash = $null
    }

    #2. If hashes match - then nothing to do
    if ($LocalHash -eq $RemoteFileHash) {
        Write-Host "Local file [$fileName] has the same hash as remote file`n" -ForegroundColor DarkGray
    }

    #3. Hashes do not match
    if ($LocalHash -ne $RemoteFileHash) {
        Write-Verbose "Local file [$fileName ] does not exist or has a different hash to the remote file"
        return $false
    } else {
        write-verbose "Local file [$fileName ] already exists and has the same hash as remote file"
        return $true
    }
}