github.com/niedbalski/juju@v0.0.0-20190215020005-8ff100488e47/cloudconfig/windowsuserdatafiles/filesha256.ps1 (about) 1 2 Function Get-FileSHA256{ 3 Param( 4 $FilePath 5 ) 6 try { 7 $hash = [Security.Cryptography.HashAlgorithm]::Create( "SHA256" ) 8 $stream = ([IO.StreamReader]$FilePath).BaseStream 9 $res = -join ($hash.ComputeHash($stream) | ForEach { "{0:x2}" -f $_ }) 10 $stream.Close() 11 return $res 12 } catch [System.Management.Automation.RuntimeException] { 13 return (Get-FileHash -Path $FilePath).Hash 14 } 15 }