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 參數搭配使用。 檔案的內容必須是 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
指定要檢查之檔案的路徑。 LiteralPath 參數值與 FilePath 不同,會完全依照其輸入值來使用。 沒有字元會被視為萬用字元。 如果路徑包含逸出字元,請將它括在單引號中。 單引號會告訴 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 |
輸入
您可以使用管線傳送包含此 Cmdlet 檔案路徑的字串。
輸出
此 Cmdlet 會針對它取得的每個簽章傳回簽章物件。
備註
此 Cmdlet 僅適用於 Windows 平臺。
如需 PowerShell 中 Authenticode 簽章的相關信息,請參閱 about_Signing。