当前位置:网站首页 > 更多 > 玩电脑 > 正文

[玩转系统] 获取 AuthenticodeSignature (Microsoft.PowerShell.Security)

作者:精品下载站 日期:2024-12-14 02:09:31 浏览:16 分类:玩电脑

获取 AuthenticodeSignature (Microsoft.PowerShell.Security)


Get-AuthenticodeSignature

模块 :Microsoft.PowerShell.Security

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

句法

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

描述

此 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参数一起使用。在 PowerShell 7.4 之前,文件的内容必须采用 Unicode (UTF-16LE) 格式。

类型 :

字节[]

位置:

命名

默认值:

None

必需的:

True

接受管道输入:

True

接受通配符:

False

-FilePath

指定要检查的文件的路径。允许使用通配符,但它们必须指向单个文件。当您指定此参数的值时,无需在命令行中键入 FilePath

类型 :

String[]

位置:

0

默认值:

None

必需的:

True

接受管道输入:

True

接受通配符:

True

-LiteralPath

指定正在检查的文件的路径。与 FilePath 不同,LiteralPath 参数的值完全按照键入的值使用。没有字符被解释为通配符。如果路径包含转义字符,请将其用单引号引起来。单引号告诉 PowerShell 不要将任何字符解释为转义字符。

类型 :

String[]

别名:

PSPath

位置:

命名

默认值:

None

必需的:

True

接受管道输入:

True

接受通配符:

False

-SourcePathOrExtension

检索其 Authenticode 签名的内容的文件或文件类型的路径。此参数与 Content 一起使用,其中文件内容作为字节数组传递。

类型 :

String[]

位置:

命名

默认值:

None

必需的:

True

接受管道输入:

True

接受通配符:

False

输入

字符串

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

输出

签名

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

笔记

此 cmdlet 仅在 Windows 平台上可用。

有关 PowerShell 中 Authenticode 签名的信息,请参阅 about_Signing。

您需要 登录账户 后才能发表评论

取消回复欢迎 发表评论:

关灯