Get-AuthenticodeSignature

获取有关文件的 Authenticode 签名的信息。

语法

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

说明

此 cmdlet 仅在 Windows 平台上可用。

Get-AuthenticodeSignature cmdlet 以字节数组形式获取有关文件或文件内容的验证码签名的信息。 如果文件同时经过嵌入式签名和 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 目录中具有有效验证码签名的所有文件。 $PSHOME 自动变量包含 PowerShell 安装目录的路径。

该命令使用 Get-ChildItem cmdlet 获取 $PSHOME 目录中的文件。 它使用 . 模式来排除目录(尽管它还会排除文件名中没有句点的文件)。

该命令使用管道运算符 (|) 将 $PSHOME 中的文件发送到 ForEach-Object cmdlet,其中将针对每个文件调用 Get-AuthenticodeSignature

Get-AuthenticodeSignature 命令的结果会发送到 Where-Object 命令,后者仅选择状态为“Valid”的签名对象。

示例 4:获取指定为字节数组的文件内容的验证码签名

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

此命令获取有关文件内容的验证码签名的信息。 在此示例中,文件扩展名与文件的内容一起指定。

参数

-Content

字节数组形式的文件的内容,会为其检索验证码签名。 此参数必须与 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

内容的文件路径或文件类型,会为其检索验证码签名。 此参数与 Content 配合使用,后一参数中的文件内容作为字节数组传递。

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

输入

String

可以通过管道将包含文件路径的字符串传递给此 cmdlet。

输出

Signature

此 cmdlet 会为每个所获取的签名返回一个签名对象。

备注

此 cmdlet 仅在 Windows 平台上可用。

有关 PowerShell 中验证码签名的详细信息,请参阅 about_Signing