syg_hira's tech memo

windows server関連のTipsのおぼえがき

Using file hash in PowerShell

I am working with PowerShell to maintenance systems.
I managed many scripts manually in this situation.
I confirmed file size and timestamp to identify the script version.

It is hard to deploy because server and script is too many.

I had made a script to enumerate filehash.

$stream = New-Object IO.StreamReader  
# MD5ハッシュ値を計算する 
$md5 = [System.Security.Cryptography.MD5]::Create() 
$hash = $md5.ComputeHash($stream.BaseStream); 
$result = [System.BitConverter]::ToString($hash).ToLower().Replace("-","") 
Write-Output $result