Giter VIP home page Giter VIP logo

get-hash-value's Introduction

Get-HashValue.ps1

OS: Windows
Type: A Windows PowerShell script
Language: Windows PowerShell
Description: Get-HashValue uses the inbuilt Get-FileHash cmdlet in machines that have PowerShell version 4 or later installed and .NET Framework in machines that are running PowerShell version 2 or 3 for file analysation and for calculating the hash values. MD5, SHA256, SHA1, SHA384, SHA512, MACTripleDES and RIPEMD160 hash values are automatically displayed for the files that are defined with the -FilePath parameter. To show only a certain hash type or a selection of the aforementioned hash types, the parameter -Algorithm may be added to the launching command.

The -FilePath parameter accepts plain filenames (then the current directory gets searched for the inputted filename) or 'FullPath' filenames, which include the path to the file as well (such as C:\Windows\explorer.exe). To enter multiple files for analysation, please separate each individual entity with a comma. If the filename or the directory name includes space characters, please enclose the whole string (the individual entity in question) in quotation marks (single or double).

If any hash values are successfully calculated, a text file (hash_values.txt) is created to $env:temp, which points to the current temporary file location and is set in the system (- for more information about $env:temp, please see the Notes section). The default output destination folder may be changed with the -Output parameter. During the possibly invoked text file creation procedure Get-HashValue tries to preserve any pre-existing content rather than overwrite the file, so if the text file already exists in the defined -Output folder, new data is appended to the end of that file. Please note that if any of the parameter values include space characters, the value should be enclosed in quotation marks (single or double) so that PowerShell can interpret the command correctly.
Homepage: https://github.com/auberginehill/get-hash-value
Short URL: http://tinyurl.com/gv3n8fn
Version: 1.2
Sources:
Emojis: Emoji Table
Twon of An: Get the SHA1,SHA256,SHA384,SHA512,MD5 or RIPEMD160 hash of a file
Gisli: Unable to read an open file with binary reader
Lee Holmes: Windows PowerShell Cookbook (O'Reilly): Get-FileHash script
Downloads: For instance Get-HashValue.ps1. Or everything as a .zip-file.

Screenshot

        screenshot

Parameters

๐Ÿ“
  • Parameter -FilePath

    with aliases -FilenameWithPathName, -FullPath, -Source, and -File. The -FilePath parameter determines, which file(s) is/are selected for hash value calculation, and in essence define the objects for Get-HashValue.

    The -FilePath parameter accepts plain filenames (then the current directory gets searched for the inputted filename) or 'FullPath' filenames, which include the path to the file as well (such as C:\Windows\explorer.exe). To enter multiple files for analysation, please separate each individual entity with a comma. If the filename or the directory name includes space characters, please enclose the whole string (the individual entity in question) in quotation marks (single or double). It's not mandatory to write -FilePath in the get hash value command to invoke the -FilePath parameter, as is shown in the Examples below, since Get-HashValue is trying to decipher the inputted queries as good as it is machinely possible within a 40 KB size limit. The -FilePath parameter also takes an array of strings and objects could be piped to this parameter, too. If no value for the -FilePath parameter is defined in the command launching Get-HashValue, the user will be prompted to enter a -FilePath value.

  • Parameter -Output

    with an alias -ReportPath. Specifies where the text file (hash_values.txt, which is created or updated with successfully calculated hash values) is to be saved. The text file includes the hash values and a timestamp, when the values were calculated. The default save location is $env:temp, which points to the current temporary file location, which is set in the system. The default -Output save location is defined at line 16 with the $Output variable. In case the path name includes space characters, please enclose the path name in quotation marks (single or double). For usage, please see the Examples below and for more information about $env:temp, please see the Notes section below.

  • Parameter -Algorithm

    with aliases -Type, -Hash, -HashType, -Version and -Algo. To enter multiple values to the -Algorithm parameter, please separate each individual entity with a comma. If the -Algorithm parameter is added to the command launching Get-HashValue, the defined types of hash values of the object file(s) are displayed and written to the text file. The valid values for -Algorithm parameter are MD5, SHA1, SHA256, SHA384, SHA512, MACTripleDES and RIPEMD160. If no -Algorithm parameter is defined in the command launching Get-HashValue, all the available hash values (i.e. MD5, SHA256, SHA1, SHA384, SHA512, MACTripleDES and RIPEMD160) are displayed and written to a text file.

Outputs

โžก๏ธ
  • Displays information about hash values in console, and if any hash values were successfully calculated, writes or updates a text file (hash_values.txt) at $env:temp by default or at the location specified with the -Output parameter.

  • Default values (the text file creation/updating procedure only occurs, if hash values are successfully calculated by Get-HashValue):
    1. Path Type Name
      $env:temp\hash_values.txt TXT-file hash_values.txt

Notes

โš ๏ธ
  • Please note that all the parameters can be used in one get hash value command and that each of the parameters can be "tab completed" before typing them fully (by pressing the [tab] key).

  • Please note that the default text file name (hash_values.txt) is defined at line 29 with the $txt_filename variable.
  • Please note that the possibly generated text file is created in a directory, which is end-user settable in each get hash value command with the -Output parameter. The default save location is defined with the $Output variable (at line 16). The $env:temp variable points to the current temp folder. The default value of the $env:temp variable is C:\Users\<username>\AppData\Local\Temp (i.e. each user account has their own separate temp folder at path %USERPROFILE%\AppData\Local\Temp). To see the current temp path, for instance a command

    [System.IO.Path]::GetTempPath()

    may be used at the PowerShell prompt window [PS>]. To change the temp folder for instance to C:\Temp, please, for example, follow the instructions at Temporary Files Folder - Change Location in Windows, which in essence are something along the lines:
    1. Right click on Computer and click on Properties (or select Start โ†’ Control Panel โ†’ System). In the resulting window with the basic information about the computer...
    2. Click on Advanced system settings on the left panel and select Advanced tab on the resulting pop-up window.
    3. Click on the button near the bottom labeled Environment Variables.
    4. In the topmost section labeled User variables both TMP and TEMP may be seen. Each different login account is assigned its own temporary locations. These values can be changed by double clicking a value or by highlighting a value and selecting Edit. The specified path will be used by Windows and many other programs for temporary files. It's advisable to set the same value (a directory path) for both TMP and TEMP.
    5. Any running programs need to be restarted for the new values to take effect. In fact, probably also Windows itself needs to be restarted for it to begin using the new values for its own temporary files.

Examples

๐Ÿ“– To open this code in Windows PowerShell, for instance:

  1. ./Get-HashValue a_certain_filename.exe
    Run the script. Please notice to insert ./ or .\ before the script name. The current directory gets searched for the inputted filename "a_certain_filename.exe") and if any hash values were successfully calculated, the text file is saved to the default location ($env:temp). During the possibly invoked text file creation procedure Get-HashValue tries to preserve any pre-existing content rather than overwrite the file, so if the text file (hash_values.txt) already exists, new data is appended to the end of that file.
  2. help ./Get-HashValue -Full
    Display the help file.
  3. ./Get-HashValue -FilePath "C:\Windows\explorer.exe" -Output "C:\Scripts"
    Run the script and get get the MD5, SHA1, SHA256, SHA384, SHA512, MACTripleDES and RIPEMD160 hash values from the "C:\Windows\explorer.exe" file and if any hash values were successfully calculated, save the text file to C:\Scripts. Please note, that -FilePath can be omitted in this example, because

    ./Get-HashValue "C:\Windows\explorer.exe" -Output "C:\Scripts"

    will result in the exact same outcome.
  4. ./Get-HashValue -Source "C:\Users\Dropbox\a certain filename.exe" -Algorithm SHA256, MD5
    Will display the SHA256 and MD5 hash values of "C:\Users\Dropbox\a certain filename.exe" in console and write them to a text file, which is saved to the default location ($env:temp). This command will work, because because -Source is an alias of -FilePath. The -FilePath (a.k.a. -Source a.k.a. -FilenameWithPathName a.k.a. -FullPath a.k.a. -File) variable value is case-insensitive (as is most of the PowerShell), but since the filename contains space characters, the whole FullPath value needs to be enveloped with quotation marks. Furthermore, the word -Source and the space character in the -Algorithm value list may be left out from this command, since, for example,

    ./Get-HashValue "c:\users\dROPBOx\A Certain Filename.exe" -Algorithm sha256,md5

    is the exact same command in nature.
  5. ./Get-HashValue -FilePath "C:\Windows\explorer.exe", "C:\Users\Dropbox\a_certain_filename.exe"
    Will display the hash values of "C:\Windows\explorer.exe" and "C:\Users\Dropbox\a_certain_filename.exe" in console and write them to a text file, which is saved to the default location ($env:temp). Since the -FilePath values don't contain any space characters, they don't need to be enveloped with quotation marks, because

    ./Get-HashValue C:\Windows\explorer.exe, C:\Users\Dropbox\a_certain_filename.exe

    would result in the same outcome.
  6. Set-ExecutionPolicy remotesigned
    This command is altering the Windows PowerShell rights to enable script execution for the default (LocalMachine) scope. Windows PowerShell has to be run with elevated rights (run as an administrator) to actually be able to change the script execution properties. The default value of the default (LocalMachine) scope is "Set-ExecutionPolicy restricted".

    Parameters:

      Restricted Does not load configuration files or run scripts. Restricted is the default execution policy.
      AllSigned Requires that all scripts and configuration files be signed by a trusted publisher, including scripts that you write on the local computer.
      RemoteSigned Requires that all scripts and configuration files downloaded from the Internet be signed by a trusted publisher.
      Unrestricted Loads all configuration files and runs all scripts. If you run an unsigned script that was downloaded from the Internet, you are prompted for permission before it runs.
      Bypass Nothing is blocked and there are no warnings or prompts.
      Undefined Removes the currently assigned execution policy from the current scope. This parameter will not remove an execution policy that is set in a Group Policy scope.

    For more information, please type "Get-ExecutionPolicy -List", "help Set-ExecutionPolicy -Full", "help about_Execution_Policies" or visit Set-ExecutionPolicy or about_Execution_Policies.

  7. New-Item -ItemType File -Path C:\Temp\Get-HashValue.ps1
    Creates an empty ps1-file to the C:\Temp directory. The New-Item cmdlet has an inherent -NoClobber mode built into it, so that the procedure will halt, if overwriting (replacing the contents) of an existing file is about to happen. Overwriting a file with the New-Item cmdlet requires using the Force. If the path name and/or the filename includes space characters, please enclose the whole -Path parameter value in quotation marks (single or double):

      New-Item -ItemType File -Path "C:\Folder Name\Get-HashValue.ps1"

    For more information, please type "help New-Item -Full".

Contributing

Find a bug? Have a feature request? Here is how you can contribute to this project:

contributing Bugs: Submit bugs and help us verify fixes.
Feature Requests: Feature request can be submitted by creating an Issue.
Edit Source Files: Submit pull requests for bug fixes and features and discuss existing proposals.

www

www Script Homepage
Twon of An: Get the SHA1,SHA256,SHA384,SHA512,MD5 or RIPEMD160 hash of a file
Gisli: Unable to read an open file with binary reader
Lee Holmes: Windows PowerShell Cookbook (O'Reilly): Get-FileHash script
SHA256CryptoServiceProvider Class
MD5CryptoServiceProvider Class
MACTripleDES Class
RIPEMD160 Class
System.Security.Cryptography Namespace
Path Methods
Test-Path
PowerShell Advanced Functions: Can we build them better?
How do I get PowerShell 4 cmdlets such as Test-NetConnection to work on Windows 7?
Get-FileHash
Calculate MD5 and SHA1 File Hashes Using PowerShell
remove-duplicate-files.ps1
Tobias Weltner: PowerTips Monthly Volume 2: Arrays and Hash Tables (or one of the archive.org versions)
Get-FileHash.ps1
ASCII Art: http://www.figlet.org/ and ASCII Art Text Generator

Related scripts

www Disable-Defrag
Firefox Customization Files
Get-AsciiTable
Get-BatteryInfo
Get-ComputerInfo
Get-CultureTables
Get-DirectorySize
Get-InstalledPrograms
Get-InstalledWindowsUpdates
Get-PowerShellAliasesTable
Get-PowerShellSpecialFolders
Get-RAMInfo
Get-TimeDifference
Get-TimeZoneTable
Get-UnusedDriveLetters
Emoji Table
Java-Update
Remove-EmptyFolders
Remove-EmptyFoldersLite
Rename-Files
Rock-Paper-Scissors
Toss-a-Coin
Update-AdobeFlashPlayer
Update-MozillaFirefox

get-hash-value's People

Contributors

auberginehill avatar

Stargazers

 avatar  avatar

Forkers

codedchaos

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.