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 檔會取得檔案的 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[] |
| 預設值: | 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, LP |
參數集
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。