Skip to content

Instantly share code, notes, and snippets.

@ciphertxt
Created March 26, 2013 11:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ciphertxt/5244838 to your computer and use it in GitHub Desktop.
Save ciphertxt/5244838 to your computer and use it in GitHub Desktop.
Backup the web.config for a given web application
$webappName = “http://intranet.contoso.com”
$backupDir = “C:\backups”
Write-Host "Backing up $webappName web.config file…" -foreground Gray –nonewline
## Get the web application – by display name
$w = Get-SPWebApplication | where { $_.DisplayName -eq "$webappName"}
## Get the default (first) zone for the web app…
## You may wish to iterate through all the available zones
$zone = $w.AlternateUrls[0].UrlZone
## Get the collection of IIS settings for the zone
$iisSettings = $w.IisSettings[$zone]
## Get the path from the settings
$path = $iisSettings.Path.ToString() + "\web.config"
## copy the web.config file from the path
copy-item $path -destination $backupDir\$webappName
Write-Host "done" -foreground Green
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment