如何获取包含在多个子文件夹中的文件的完整数字签名信息
How to get the complete Digital signature info's of files containing in multiple sub folders
我绝对是编码初学者,我的问题是如何检索包含在多个子文件夹中的文件的数字证书的完整详细信息(导出到 csv)。在 google 的帮助下,我发现下面的 powershell 代码足以满足单个文件的需求。
get-childitem C:\Windows\notepad.exe | Get-AuthenticodeSignature |Format-List
我在多个子文件夹中有 300 多个文件 (exe/DLLS)。
我什么
- 获取所有文件的详细信息,包括子文件夹中的文件。
- 将详细信息导出到 csv。 attached image file
- 列 headers > SignerCertificate:主题,SignerCertificate:颁发者,SignerCertificate:序列号,SignerCertificate:不是之前,SignerCertificate:不是之后, SignerCertificate:指纹,TimeStamperCertificate:主题,TimeStamperCertificate:颁发者,TimeStamperCertificate:序列号,TimeStamperCertificate:不在之前,TimeStamperCertificate:不在之后,TimeStamperCertificate:指纹,状态,StatusMessage,路径
如果您知道所有文件的路径,您可以将它们全部添加到 .csv,然后 运行 一个包含所有文件的带有 ForEach 循环的脚本。
csv 格式示例:
那么你可以试试下面的脚本:
编辑: 根据圣地亚哥删除了 System.Array
。
# Make an array containing all FilePaths by importing the .csv file to a variable
$Files = (Import-Csv C:\Path\To\Import.csv).FilePath
# Run the script for each $File in the $Files array
$AllFilesExport = ForEach($File in $Files) {
# Get the information you want about the file
$FileInfo = Get-ChildItem $File | Get-AuthenticodeSignature
# Specify the Column name (left) and what data it should have in it (right)
[pscustomobject]@{
'SignerCertificate:Subject' = $FileInfo.SignerCertificate.Subject
'SignerCertificate: Issuer' = $FileInfo.SignerCertificate.Issuer
'SignerCertificate: Serial Number' = $FileInfo.SignerCertificate.SerialNumber
'SignerCertificate: Not Before' = $FileInfo.SignerCertificate.NotBefore
'SignerCertificate: Not After' = $FileInfo.SignerCertificate.NotAfter
'SignerCertificate: Thumbprint' = $FileInfo.SignerCertificate.Thumbprint
'TimeStamperCertificate: Subject' = $FileInfo.TimeStamperCertificate.Subject
'TimeStamperCertificate: Issuer' = $FileInfo.TimeStamperCertificate.Issuer
'TimeStamperCertificate: Serial Number' = $FileInfo.TimeStamperCertificate.SerialNumber
'TimeStamperCertificate: Not Before' = $FileInfo.TimeStamperCertificate.NotBefore
'TimeStamperCertificate: Not After' = $FileInfo.TimeStamperCertificate.NotAfter
'TimeStamperCertificate: Thumbprint' = $FileInfo.TimeStamperCertificate.Thumbprint
'Status' = $FileInfo.Status
'StatusMessage' = $FileInfo.StatusMessage
'Path' = $FileInfo.Path
}
}
# Export all of the file information from the AllFileExport array into an export .csv file
$AllFilesExport | Export-Csv -NoTypeInformation C:\Path\To\Export.csv
我绝对是编码初学者,我的问题是如何检索包含在多个子文件夹中的文件的数字证书的完整详细信息(导出到 csv)。在 google 的帮助下,我发现下面的 powershell 代码足以满足单个文件的需求。
get-childitem C:\Windows\notepad.exe | Get-AuthenticodeSignature |Format-List
我在多个子文件夹中有 300 多个文件 (exe/DLLS)。 我什么
- 获取所有文件的详细信息,包括子文件夹中的文件。
- 将详细信息导出到 csv。 attached image file
- 列 headers > SignerCertificate:主题,SignerCertificate:颁发者,SignerCertificate:序列号,SignerCertificate:不是之前,SignerCertificate:不是之后, SignerCertificate:指纹,TimeStamperCertificate:主题,TimeStamperCertificate:颁发者,TimeStamperCertificate:序列号,TimeStamperCertificate:不在之前,TimeStamperCertificate:不在之后,TimeStamperCertificate:指纹,状态,StatusMessage,路径
如果您知道所有文件的路径,您可以将它们全部添加到 .csv,然后 运行 一个包含所有文件的带有 ForEach 循环的脚本。
csv 格式示例:
那么你可以试试下面的脚本:
编辑: 根据圣地亚哥删除了 System.Array
。
# Make an array containing all FilePaths by importing the .csv file to a variable
$Files = (Import-Csv C:\Path\To\Import.csv).FilePath
# Run the script for each $File in the $Files array
$AllFilesExport = ForEach($File in $Files) {
# Get the information you want about the file
$FileInfo = Get-ChildItem $File | Get-AuthenticodeSignature
# Specify the Column name (left) and what data it should have in it (right)
[pscustomobject]@{
'SignerCertificate:Subject' = $FileInfo.SignerCertificate.Subject
'SignerCertificate: Issuer' = $FileInfo.SignerCertificate.Issuer
'SignerCertificate: Serial Number' = $FileInfo.SignerCertificate.SerialNumber
'SignerCertificate: Not Before' = $FileInfo.SignerCertificate.NotBefore
'SignerCertificate: Not After' = $FileInfo.SignerCertificate.NotAfter
'SignerCertificate: Thumbprint' = $FileInfo.SignerCertificate.Thumbprint
'TimeStamperCertificate: Subject' = $FileInfo.TimeStamperCertificate.Subject
'TimeStamperCertificate: Issuer' = $FileInfo.TimeStamperCertificate.Issuer
'TimeStamperCertificate: Serial Number' = $FileInfo.TimeStamperCertificate.SerialNumber
'TimeStamperCertificate: Not Before' = $FileInfo.TimeStamperCertificate.NotBefore
'TimeStamperCertificate: Not After' = $FileInfo.TimeStamperCertificate.NotAfter
'TimeStamperCertificate: Thumbprint' = $FileInfo.TimeStamperCertificate.Thumbprint
'Status' = $FileInfo.Status
'StatusMessage' = $FileInfo.StatusMessage
'Path' = $FileInfo.Path
}
}
# Export all of the file information from the AllFileExport array into an export .csv file
$AllFilesExport | Export-Csv -NoTypeInformation C:\Path\To\Export.csv