共用方式為


Get-AuthenticodeSignature

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

語法

ByPath (預設值)

Get-AuthenticodeSignature
    [-FilePath] <String[]>
    [<CommonParameters>]

ByLiteralPath

Get-AuthenticodeSignature
    -LiteralPath <String[]>
    [<CommonParameters>]

ByContent

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 簽章

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

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

參數

-Content

檔案內容轉換為位元組陣列,以便提取 Authenticode 簽章。 此參數必須與 SourcePathOrExtension 參數搭配使用。 檔案的內容必須是 Unicode (UTF-16LE) 格式。

參數屬性

類型:

Byte[]

預設值:None
支援萬用字元:False
不要顯示:False

參數集

ByContent
Position:Named
必要:True
來自管線的值:False
來自管線按屬性名稱的值:True
來自剩餘引數的值:False

-FilePath

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

參數屬性

類型:

String[]

預設值:None
支援萬用字元:True
不要顯示:False

參數集

ByPath
Position:0
必要:True
來自管線的值:True
來自管線按屬性名稱的值:True
來自剩餘引數的值:False

-LiteralPath

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

參數屬性

類型:

String[]

預設值:None
支援萬用字元:False
不要顯示:False
別名:PSPath

參數集

ByLiteralPath
Position:Named
必要:True
來自管線的值:False
來自管線按屬性名稱的值:True
來自剩餘引數的值:False

-SourcePathOrExtension

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

參數屬性

類型:

String[]

預設值:None
支援萬用字元:False
不要顯示:False

參數集

ByContent
Position:Named
必要:True
來自管線的值:True
來自管線按屬性名稱的值:True
來自剩餘引數的值:False

CommonParameters

此 Cmdlet 支援一般參數:-Debug、-ErrorAction、-ErrorVariable、-InformationAction、-InformationVariable、-OutBuffer、-OutVariable、-PipelineVariable、-ProgressAction、-Verbose、-WarningAction 和 -WarningVariable。 如需詳細資訊,請參閱 about_CommonParameters

輸入

String

您可以將包含檔案路徑的字串透過管線傳送給此 Cmdlet。

輸出

Signature

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

備註

此 Cmdlet 僅適用於 Windows 平臺。

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