

I recently had a situation where I needed to be able to deploy only changed files from a set of files. The file objects for the resultant modified files were returned because -PassThru was used. In the above example 1.txt was in the source path but not in the destination path so was created and then copied, 2.txt was found to be different in the source path and so was overwritten. Here is an example of Copy-FileHash in action:
Powershell checksum install#
If you want to go directly to the code, you can find it in GitHub here, or you can install it from the PowerShell Gallery by executing:įor full details on how the cmdlet works.Ĭopy-FileHash requires Windows PowerShell version 4 or above, or PowerShell Core version 6 or above (through which the cmdlet should work on MacOS, Ubuntu or Windows). – Source: Get-FileHash Official Documentation However, changing even a single character in the contents of a file changes the hash value of the file.” Similarly, the file’s content can be changed without changing the name or extension. File names and extensions can be changed without altering the content of the file, and without changing the hash value. Rather than identifying the contents of a file by its file name, extension, or other designation, a hash assigns a unique value to the contents of a file. “A hash value is a unique value that corresponds to the content of the file. This might be useful if you need to copy just files that have been modified between two paths and aren’t able to rely on the modified date of those files to determine which have changed.

The cmdlet determines which files have different contents by calculating their hash values through the Get-FileHash cmdlet. This blog post details a PowerShell Core compatible cmdlet that I have authored named Copy-FileHash that you can use to copy modified files from one path tree to another.
