Backup all Exchange Web.Config files with PowerShell

With so many exchange server being migrated to Office 365, this requires the latest CU updates to be installed prior to migration and one of the side effects of installing CU updates is that the .confg files are overwritten during upgrade so they all need updating.

The problem is it’s time consuming finding and backing these up manually (whilst keeping the folder structure and file names as they are mostly all called web.config) so I have written some PowerShell to do this for us.

$backuplocation = "C:\users\administrator\desktop\WebConfigBackup\"
 $exchpath = "C:\Program Files\Microsoft\Exchange Server\V15\"
 $configfiles = Get-ChildItem -Path $exchpath -Filter *.config -Recurse | ForEach-Object {
 $filepath = $_.FullName.Replace($exchpath,'')
 $destination = "$backuplocation$filepath"
 New-Item -ItemType File -Path $destination -Force
 Copy-Item -Path $filepath -Destination $destination -Force

Your Welcome 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *