Powershell script to backup and replace files -
i'm working on project deployment tool automatically adds ".update" extension if same file exists on destination. e.g.
root web.config web.config.update connection.config connection.config.update
i perform following post-deploy via powershell:
- backup *.config.
replace existing *.config *.update file. below desired ouput:
root web.config web.config.update connection.config connection.config.update root web.config connection.config backup web.config connection.config
could please how above achieved using powershell?
the following code perform want.
- backs existing config files backup folder named based on current date.
replace existing config files deleting them , renaming update files.
$root_folder = 'c:\temp\root' # create backup folder $backup_directory = new-item -path "$root_folder\backup_$(get-date -format yyyymmdd)" -force -itemtype directory get-childitem -filter *.config | foreach-object { # copy .config files backup directory copy-item -path $_.fullname -destination "$($backup_directory.fullname)" -force # delete file source directory $_ | remove-item # rename .update files .config files. rename-item -path "$($_.fullname).update" -newname $_.fullname -force }
Comments
Post a Comment