Get-AuthenticodeSignature
获取有关文件的 Authenticode 签名的信息。
语法
Get-AuthenticodeSignature
[-FilePath] <String[]>
[<CommonParameters>]
Get-AuthenticodeSignature
-LiteralPath <String[]>
[<CommonParameters>]
Get-AuthenticodeSignature
-SourcePathOrExtension <String[]>
-Content <Byte[]>
[<CommonParameters>]
说明
cmdlet Get-AuthenticodeSignature
以字节数组的形式获取有关文件或文件内容的 Authenticode 签名的信息。 如果文件未签名,则将检索信息,但字段为空。
示例
示例 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
。 自动 $PSHOME
变量包含 PowerShell 安装目录的路径。
命令使用 Get-ChildItem
cmdlet 获取 目录中的文件 $PSHOME
。 它使用 的 模式来排除目录 (但它也排除文件名) 中没有点的文件。
命令使用管道运算符 (|
) 将文件$PSHOME
ForEach-Object
发送到 cmdlet,其中 Get-AuthenticodeSignature
为每个文件调用 。
命令的结果 Get-AuthenticodeSignature
将发送到 Where-Object
仅选择状态为“有效”的签名对象的命令。
示例 4:获取指定为字节数组的文件内容的验证码签名
Get-AuthenticodeSignature -Content (Get-Content foo.ps1 -AsByteStream) -SourcePathorExtension ps1
此命令获取有关文件内容的验证码签名的信息。 在此示例中,文件扩展名与文件的内容一起指定。
参数
-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
指定要检查的文件的路径。 与 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 |
输入
可以通过管道将包含文件路径的字符串传递给 Get-AuthenticodeSignature
。
输出
Get-AuthenticodeSignature
为它获取的每个签名返回一个签名对象。
备注
此 cmdlet 仅在 Windows 平台上可用。
有关 PowerShell 中的 Authenticode 签名的信息,请参阅 about_Signing。