Skip to content

Instantly share code, notes, and snippets.

@lunatilia
Created March 13, 2015 15:31
Show Gist options
  • Save lunatilia/ebe3025dd46f9cb85444 to your computer and use it in GitHub Desktop.
Save lunatilia/ebe3025dd46f9cb85444 to your computer and use it in GitHub Desktop.
ファイルのチェックサムを取得するPowerShellスクリプト for PowerShell 3.0
# Get-Checksum.ps1: File Checksum Integrity Verifier
Param(
[string] $filename,
[string] $algorithm = ( 'sha1' ),
[switch] $help
)
Function Calc-Hash
{
$fileStream = [system.io.file]::openread( ( resolve-path $filename ) )
$hash = [System.Security.Cryptography.HashAlgorithm]::create( $algorithm ).ComputeHash( $fileStream )
$fileStream.close()
$fileStream.dispose()
$value = [System.BitConverter]::ToString( $hash ).Replace( "-", "" ).ToLower()
Write-Host "$value $filename"
}
Function View-Help
{
Write-Host "Usage: Get-Checksum [OPTION]... [FILE]...
Print or check checksums.
OPTIONS:
-a, -algorithm md5, sha1, sha256, sha384, sha512, mactripledes, ripemd160
-h, -help Display this help.
EXAMPLES:
Get-Checksum filename.zip
Get-Checksum -a md5 filename.zip
"
}
Function Get-Options
{
If( $help ) {
View-Help
} elseif( !$filename ) {
Write-Host "Missing filename. (`"Get-Checksum -help`" )"
} else {
Calc-Hash
}
}
Get-Options
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment