0

I am wondering if anyone can give me some insight as to how to setup a script that will look at a folder on your computer (say C:\Windows\System32) and be able to look at the files within the folder to compare against a predefined Hash Table.

This Hash table will have information about identical files found in the "system32" folder and then locate the files that have wrong versions. The hash table will consist of Files and their versions.

Example:
advapi32.dll 6.1.7600.16385 comctl32.dll 6.1.7600.16385 comdlg32.dll 6.1.7600.16385 gdi32.dll 6.1.7600.16385

After files with wrong versions are found, the output would list the files in question in a table format.

I know I have to use [System.Diagnostics.FileVersionInfo] to find a method that helps get the version info for a file. I know I'd have to use the .productVersion property for my comparison.

I'm not sure how to get started. If there's more info you need, please let me know.

learn2code
  • 19
  • 6
  • How are you not sure how to get started? Have you tried getting some files? Getting some file versions? Using a HashTable? Comparing two things? – TessellatingHeckler Mar 21 '14 at 03:58
  • I have the hash table but i'm trying to figure out how to compare the values in the table to a folder parameter such as System32. – learn2code Mar 21 '14 at 04:04
  • I'm unclear about what is in the hash table. A hash table has keys and values. What are the keys and values in this case? – dan-gph Mar 21 '14 at 04:53
  • files and versions. Example: advapi32.dll 6.1.7600.16385 comctl32.dll 6.1.7600.16385 comdlg32.dll 6.1.7600.16385 gdi32.dll 6.1.7600.16385 – learn2code Mar 21 '14 at 05:01

1 Answers1

0

I'm lost as to where you're stuck. If you need the files in a folder, and you aren't googling "files in folder powershell" then ... what are you doing?

Your previous two questions and answers include using: if / equality testing, gci (get-childitem), using that to get a filename with path, calling .Net framework functions. That's mostly all you need, all they are missing is the hashtable and a loop:

$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)"
    }
}
TessellatingHeckler
  • 27,511
  • 4
  • 48
  • 87
  • Thanks for the help TessellatingHeckler. I'm still trying to make sense of things, I thought the question post had enough details to give some direction. I'm having difficulty learning and grasping the concepts...so connecting the dots have been a challenge for me. But I appreciate your efforts; it's helped! – learn2code Mar 21 '14 at 18:52