27 lines
No EOL
672 B
PowerShell
27 lines
No EOL
672 B
PowerShell
function Test-Signature{
|
|
param(
|
|
[string]$FilePath,
|
|
[string]$ExpectedCN
|
|
)
|
|
|
|
try{
|
|
$signature = Get-AuthenticodeSignature -FilePath $FilePath
|
|
|
|
if(-not ($signature.SignerCertificate.Verify())){
|
|
Write-Warning "Verify of $FilePath failed."
|
|
return $false
|
|
}
|
|
|
|
$match = $signature.SignerCertificate.Subject -eq $ExpectedCN
|
|
|
|
if(-not $match){
|
|
Write-Warning "Signature verification of $FilePath failed. Signature mismatch. Expected: >$ExpectedCN< Got: $($signature.SignerCertificate.Subject)"
|
|
}
|
|
|
|
return $match
|
|
}
|
|
catch{
|
|
return $false
|
|
}
|
|
|
|
} |