none
Creating Arrays to compare File Hashes RRS feed

  • Question

  • Not sure how I could go about creating two arrays to check file integrity.... Using two sets of arrays, first set for file name, and second set for hash values.

    something like,

    $Files = @()

    $Files = "file1.ps1"

    $Files += "file2.ps1"

    $Hash = @()

    $Hash = "HASHVALUEFORFILE1"

    $Hash = "HASHVALUEFORFILE2"

    ......additional files and hashes

    Foreach ($File in $Files) {

    If ((Get-FileHash $File).hash -eq $Hash) {

    Write-host "$File  Hash mismatch" 

    #disable script

    #send email

    }

    }


    • Edited by JT_CP Saturday, November 12, 2016 12:23 AM
    Saturday, November 12, 2016 12:11 AM

Answers

  • use hash tables

    man about_Hash_Tables

    $Files=@{}
    $Files["File1.ps1"]="HASHVALUEFORFILE1"
    $Files["File2.ps1"]="HASHVALUEFORFILE2"
    #
    $Files["File1.ps1"]



    my blog: http://shserg.ru/

    Monday, November 14, 2016 10:56 PM

All replies

  • Like this:


    $Files = @()
    $Files += "file1.ps1"
    $Files += "file2.ps1"
    $Hash = @()
    $Hash += "HASHVALUEFORFILE1"
    $Hash += "HASHVALUEFORFILE2"


    \_(ツ)_/

    Saturday, November 12, 2016 12:52 AM
  • Or this:

    $Files = "file1.ps1","file2.ps1"
    $Hash = "HASHVALUEFORFILE1","HASHVALUEFORFILE2"


    \_(ツ)_/

    Saturday, November 12, 2016 12:53 AM
  • Better:

    $files @(
    	@('file1.ps1','hash1'),
    	@('file2.ps1','hash2')
    )
    
    Foreach ($f in $files){
    	If ((Get-FileHash $f[0]).hash -ne $f[1]){
    		Write-host "$($f[0])  Hash mismatch"
    	}
    }
    


    \_(ツ)_/

    Saturday, November 12, 2016 12:58 AM
  • use hash tables

    man about_Hash_Tables

    $Files=@{}
    $Files["File1.ps1"]="HASHVALUEFORFILE1"
    $Files["File2.ps1"]="HASHVALUEFORFILE2"
    #
    $Files["File1.ps1"]



    my blog: http://shserg.ru/

    Monday, November 14, 2016 10:56 PM