Private/Get-CodeSignatureInfo.ps1
|
function Get-CodeSignatureInfo { param([string]$Path) if (-not (Test-Path -LiteralPath $Path)) { return [pscustomobject]@{ Identifier = "" TeamIdentifier = "" Authority = "" Vendor = "" Signed = $false Raw = "" } } $raw = /usr/bin/codesign -dv --verbose=4 "$Path" 2>&1 $rawText = ($raw -join "`n") $identifier = (($raw | Where-Object { $_ -match "^Identifier=" }) -replace "^Identifier=", "") -join "; " $teamId = (($raw | Where-Object { $_ -match "^TeamIdentifier=" }) -replace "^TeamIdentifier=", "") -join "; " $authority = (($raw | Where-Object { $_ -match "^Authority=" }) -replace "^Authority=", "") -join "; " $vendor = "" $devAuthority = $raw | Where-Object { $_ -match "^Authority=Developer ID Application:" } | Select-Object -First 1 if ($devAuthority) { $vendor = ($devAuthority -replace "^Authority=Developer ID Application:\s*", "") # Strip trailing Team-ID parenthetical, e.g. " (ABCD1234EF)" $vendor = ($vendor -replace '\s+\([A-Z0-9]+\)$', '').Trim() } if ([string]::IsNullOrWhiteSpace($vendor)) { $appleAuthority = $raw | Where-Object { $_ -match "^Authority=Apple" } | Select-Object -First 1 if ($appleAuthority) { $vendor = "Apple" } } [pscustomobject]@{ Identifier = $identifier TeamIdentifier = $teamId Authority = $authority Vendor = $vendor Signed = ($rawText -notmatch "code object is not signed") Raw = $rawText } } |