Get-AuthenticodeSignature

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

Syntax

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

Description

此 Cmdlet 僅適用於 Windows 平臺。

Cmdlet 會 Get-AuthenticodeSignature 取得檔案或檔案內容之 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"}

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

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

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

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

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

Get-AuthenticodeSignature -Content (Get-Content foo.ps1 -AsByteStream) -SourcePathorExtension ps1

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

參數

-Content

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

Type:Byte[]
Position:Named
Default value:None
Required:True
Accept pipeline input:True
Accept wildcard characters:False

-FilePath

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

Type:String[]
Position:0
Default value:None
Required:True
Accept pipeline input:True
Accept wildcard characters:True

-LiteralPath

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

Type:String[]
Aliases:PSPath
Position:Named
Default value:None
Required:True
Accept pipeline input:True
Accept wildcard characters:False

-SourcePathOrExtension

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

Type:String[]
Position:Named
Default value:None
Required:True
Accept pipeline input:True
Accept wildcard characters:False

輸入

String

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

輸出

Signature

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

備註

此 Cmdlet 僅適用於 Windows 平臺。

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