共用方式為


Get-AuthenticodeSignature

取得檔案之 Authenticode 簽章的相關信息。

語法

Get-AuthenticodeSignature
   [-FilePath] <String[]>
   [<CommonParameters>]
Get-AuthenticodeSignature
   -LiteralPath <String[]>
   [<CommonParameters>]
Get-AuthenticodeSignature
   -SourcePathOrExtension <String[]>
   -Content <Byte[]>
   [<CommonParameters>]

Description

此 Cmdlet 只能在 Windows 平臺上使用。

Get-AuthenticodeSignature Cmdlet 會取得檔案或檔案內容做為位元組陣列之 Authenticode 簽章的相關信息。 如果檔案同時內嵌簽署和 Windows 目錄簽署,則會使用 Windows 類別目錄簽章。 如果未簽署檔案,則會擷取資訊,但字段是空白的。

範例

範例 1:取得檔案的 Authenticode 簽章

Get-AuthenticodeSignature -FilePath "C:\Test\NewScript.ps1"

此命令會取得 NewScript.ps1 檔案中 Authenticode 簽章的相關信息。 它會使用 FilePath 參數來指定檔案。

範例 2:取得多個檔案的 Authenticode 簽章

Get-AuthenticodeSignature test.ps1, test1.ps1, sign-file.ps1, makexml.ps1

此命令會取得命令行所列四個檔案的 Authenticode 簽章相關信息。 在此範例中,會省略 FilePath 參數的名稱,這是選擇性的。

範例 3:只取得多個檔案的有效 Authenticode 簽章

Get-ChildItem $PSHOME\*.* | ForEach-Object {Get-AuthenticodeSignature $_} |
    Where-Object {$_.Status -eq "Valid"}

此命令會列出 $PSHOME 目錄中具有有效 Authenticode 簽章的所有檔案。 $PSHOME 自動變數包含PowerShell安裝目錄的路徑。

命令會使用 Get-ChildItem Cmdlet 來取得 $PSHOME 目錄中的檔案。 它會使用 的模式。 排除目錄(雖然它也會排除檔名中沒有點的檔案)。

命令會使用管線運算符 (|) 將 $PSHOME 中的檔案傳送至 ForEach-Object Cmdlet,其中會針對每個檔案呼叫 Get-AuthenticodeSignature

Get-AuthenticodeSignature 命令的結果會傳送至 Where-Object 命令,只選取狀態為 Valid 的簽章物件。

範例 4:取得指定為位元組數組之檔案內容的 Authenticode 簽章

$authenticodeSignatureParams = @{
    Content = (Get-Content foo.ps1 -AsByteStream)
    SourcePathorExtension = "ps1"
}
Get-AuthenticodeSignature @authenticodeSignatureParams

此命令會取得檔案內容的 Authenticode 簽章相關信息。 在此範例中,會指定擴展名以及檔案的內容。

參數

-Content

檔案的內容做為擷取 Authenticode 簽章的位元組數位。 此參數必須與 SourcePathOrExtension 參數搭配使用。 在 PowerShell 7.4 之前,檔案的內容必須是 Unicode (UTF-16LE) 格式。

類型:Byte[]
Position:Named
預設值:None
必要:True
接受管線輸入:True
接受萬用字元:False

-FilePath

指定要檢查之檔案的路徑。 允許通配符,但必須導致單一檔案。 當您指定此參數的值時,不需要在命令行輸入 FilePath

類型:String[]
Position:0
預設值:None
必要:True
接受管線輸入:True
接受萬用字元:True

-LiteralPath

指定要檢查之檔案的路徑。 與 filePath 不同,LiteralPath 參數的值會與類型完全相同。 不會將任何字元解譯為通配符。 如果路徑包含逸出字元,請以單引弧括住它。 單引號會告知 PowerShell 不要將任何字元解譯為逸出字元。

類型:String[]
別名:PSPath, LP
Position:Named
預設值:None
必要:True
接受管線輸入:True
接受萬用字元:False

-SourcePathOrExtension

擷取 Authenticode 簽章之內容的檔案或文件類型路徑。 此參數會與 Content 搭配使用,其中檔案內容會以位元組陣列的形式傳遞。

類型:String[]
Position:Named
預設值:None
必要:True
接受管線輸入:True
接受萬用字元:False

輸入

String

您可以使用管線將包含檔案路徑的字串傳送至此 Cmdlet。

輸出

Signature

此 Cmdlet 會針對它取得的每個簽章傳回簽章物件。

備註

此 Cmdlet 僅適用於 Windows 平臺。

如需 PowerShell 中 Authenticode 簽章的相關信息,請參閱 about_Signing