Skip to content

Instantly share code, notes, and snippets.

@absolutejam
Last active March 2, 2016 10:38
Show Gist options
  • Save absolutejam/c0d7cf9142080e5f6942 to your computer and use it in GitHub Desktop.
Save absolutejam/c0d7cf9142080e5f6942 to your computer and use it in GitHub Desktop.
DCM - Keep file up to date
$FileToCopyPath = '\\MyFileSrv01\MyShare\MyFile.doc'
$FileToCheckPath = 'C:\Program Files\My Program\MyFile.doc'
If (!(Test-Path $FileToCheckPath)) {
Return 'False'
Break
} else {
$FileToCopyMD5 = New-Object -TypeName System.Security.Cryptography.MD5CryptoServiceProvider
$FileToCopyHash = [System.BitConverter]::ToString($FileToCopyMD5.ComputeHash([System.IO.File]::ReadAllBytes($FileToCopyPath)))
$FileToCheckMD5 = New-Object -TypeName System.Security.Cryptography.MD5CryptoServiceProvider
$FileToCheckHash = [System.BitConverter]::ToString($FileToCheckMD5.ComputeHash([System.IO.File]::ReadAllBytes($FileToCheckPath)))
if ($FileToCopyHash -eq $FileToCheckHash) {
Return 'True'
} else {
Return 'False'
}
}
$FileToCopyPath = '\\MyFileSrv01\MyShare\MyFile.doc'
$FileToCheckPath = 'C:\Program Files\My Program\MyFile.doc'
Copy-Item -Path $FileToCopyPath -Destination $FileToCheckPath -Force
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment