< Back

Copy-FileHash

Tue Jan 14, 2020 12:42 am

NAME Copy-FileHash



SYNOPSIS

Copies files from one location to another based on determining change via computed hash value.





SYNTAX

Copy-FileHash -Path <String[]> -Destination <String> [-Algorithm <String>] [-PassThru] [-Recurse] [-Force]

[-WhatIf] [-Confirm] [<CommonParameters>]



Copy-FileHash -LiteralPath <String[]> -Destination <String> [-Algorithm <String>] [-PassThru] [-Recurse] [-Force]

[-WhatIf] [-Confirm] [<CommonParameters>]





DESCRIPTION

The Copy-FileHash cmdlet uses the Get-FileHash cmdlet to compute the hash value of one or more files and then

copies any changed

and new files to the specified destination path. If you use the -Recurse parameter the cmdlet will synchronise a

full directory

tree, preserving the structure and creating any missing directories in the destination path as required.



The purpose of this cmdlet is to copy specific file changes between two paths in situations where you cannot rely

on the modified

date of the files to determine if a file has changed. This can occur in situations where file modified dates have

been changed, such

as when cloning a set of files from a source control system.





PARAMETERS

-Path <String[]>

The path to the source file/s or folder/s to copy any new or changed files from.



Required? true

Position? named

Default value

Accept pipeline input? true (ByValue, ByPropertyName)

Accept wildcard characters? false



-LiteralPath <String[]>

The literal path to the source file/s or folder/s to copy any new or changed files from. Unlike the Path

parameter, the value of

LiteralPath is used exactly as it is typed. No characters are interpreted as wildcards.



Required? true

Position? named

Default value

Accept pipeline input? true (ByPropertyName)

Accept wildcard characters? false



-Destination <String>

The Destination folder to compare to -Path and overwrite with any changed or new files from -Path. If the

folder does not exist

It will be created.



Required? true

Position? named

Default value

Accept pipeline input? false

Accept wildcard characters? false



-Algorithm <String>

Specifies the cryptographic hash function to use for computing the hash value of the contents of the specified

file. A cryptographic

hash function includes the property that it is not possible to find two distinct inputs that generate the same

hash values. Hash

functions are commonly used with digital signatures and for data integrity. The acceptable values for this

parameter are:



SHA1 | SHA256 | SHA384 | SHA512 | MACTripleDES | MD5 | RIPEMD160



If no value is specified, or if the parameter is omitted, the default value is SHA256.



Required? false

Position? named

Default value SHA256

Accept pipeline input? false

Accept wildcard characters? false



-PassThru [<SwitchParameter>]

Returns the output of the file copy as an object. By default, this cmdlet does not generate any output.



Required? false

Position? named

Default value False

Accept pipeline input? false

Accept wildcard characters? false



-Recurse [<SwitchParameter>]

Indicates that this cmdlet performs a recursive copy.



Required? false

Position? named

Default value False

Accept pipeline input? false

Accept wildcard characters? false



-Force [<SwitchParameter>]

Indicates that this cmdlet will copy items that cannot otherwise be changed, such as copying over a read-only

file or alias.



Required? false

Position? named

Default value False

Accept pipeline input? false

Accept wildcard characters? false



-WhatIf [<SwitchParameter>]



Required? false

Position? named

Default value

Accept pipeline input? false

Accept wildcard characters? false



-Confirm [<SwitchParameter>]



Required? false

Position? named

Default value

Accept pipeline input? false

Accept wildcard characters? false



<CommonParameters>

This cmdlet supports the common parameters: Verbose, Debug,

ErrorAction, ErrorVariable, WarningAction, WarningVariable,

OutBuffer, PipelineVariable, and OutVariable. For more information, see

about_CommonParameters (https:/go.microsoft.com/fwlink/?LinkID=113216).



INPUTS



OUTPUTS



-------------------------- EXAMPLE 1 --------------------------



PS C:\\>Copy-FileHash -Path C:\\Some\\Files -Destination D:\\Some\\Other\\Files -Recurse



Compares the files between the two trees and replaces in the destination any where they have different contents as

determined

via hash value comparison.











RELATED LINKS