Created
April 19, 2021 02:59
-
-
Save oshea00/1628d2d8ff3844113e3ef2dd6c2453ba to your computer and use it in GitHub Desktop.
Update an existing file - see comments
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This script assumes it is being run from powershell "run as administrator" prompt. | |
# | |
# The script will check if it has already been run (FileBackupTo already exists), | |
# otherwise it will backup the target FileToUpdate and replace it with the $NewFile. | |
# It sets the updated file to "read only" | |
# The following paths must be updated as needed: | |
# The current assumption is $NewFile is in the same directory as this script, | |
$FileToUpdate = "C:\Program Files\ATT Metrology\LTASWpf\LTAS30Block20.xit64" | |
$FileBackupTo = "C:\Program Files\ATT Metrology\LTASWpf\LTAS30Block20.xit64.old2021FrameUpdate" | |
$NewFile = ".\LTAS30Block20.xit64" | |
function updateFile() | |
{ | |
if (-not(Test-Path -Path $FileBackupTo -PathType Leaf)) { | |
try { | |
Write-Host "Backing up and updating [$FileToUpdate] template..." | |
Rename-Item -Path $FileToUpdate -NewName $FileBackupTo | |
Copy-Item $NewFile -Destination $FileToUpdate | |
$status = Get-ChildItem $FileToUpdate | |
$status.set_isreadonly($true) | |
} | |
catch { | |
throw $_.Exception.Message | |
} | |
} | |
else { | |
Write-Host "Aborting. [$FileBackupTo] backup already exists." | |
} | |
} | |
updateFile | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment