0

我想知道是否有人可以让我了解如何设置一个脚本来查看您计算机上的文件夹(例如 C:\Windows\System32)并能够查看文件夹中的文件以与预定义的哈希表。

此哈希表将包含有关在“system32”文件夹中找到的相同文件的信息,然后定位具有错误版本的文件。哈希表将包含文件及其版本。

例子:
advapi32.dll 6.1.7600.16385 comctl32.dll 6.1.7600.16385 comdlg32.dll 6.1.7600.16385 gdi32.dll 6.1.7600.16385

找到错误版本的文件后,输出将以表格格式列出有问题的文件。

我知道我必须使用 [System.Diagnostics.FileVersionInfo] 来查找有助于获取文件版本信息的方法。我知道我必须使用该.productVersion属性进行比较。

我不知道如何开始。如果您需要更多信息,请告诉我。

4

1 回答 1

0

我不知道你被困在哪里。如果您需要文件夹中的文件,并且您没有在谷歌上搜索“powershell 文件夹中的文件”,那么……您在做什么?

您之前的两个问题和答案包括使用:if / 相等测试、gci (get-childitem)、使用它来获取带有路径的文件名、调用 .Net 框架函数。这就是你所需要的,他们所缺少的只是哈希表和一个循环:

$files = @(Get-ChildItem -File "C:\Windows\system32\")    #NB. @() forces a one-item answer to still be an array

foreach ($file in $files) {
    $fileVersion = [System.Diagnostics.FileVersionInfo]::GetVersionInfo($file.FullName).ProductVersion
    $hashVersion = $hash[$file.Name]

    if ($hashVersion -ne $fileVersion) {
        write "$($file.Name) is different (file: $fileVersion, expected: $hashVersion)"
    }
}
于 2014-03-21T05:39:01.707 回答