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:

  1. backup *.config.
  2. 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.

  1. backs existing config files backup folder named based on current date.
  2. 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

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -