Skip to content

Instantly share code, notes, and snippets.

@phaniav
Created November 21, 2017 11:52
Show Gist options
  • Save phaniav/8079beaa7dace6035691fad1d831ff18 to your computer and use it in GitHub Desktop.
Save phaniav/8079beaa7dace6035691fad1d831ff18 to your computer and use it in GitHub Desktop.
sample script to take a sql server database backup using powershell
Set-Location "SQLSERVER:\SQL\Computer\Instance\Databases"
SQLSERVER:\SQL\Computer\Instance\Databases> ForEach($database in (Get-ChildItem)) {
$dbName = $database.Name
Backup-SqlDatabase -Database $dbName -BackupFile "\\mainserver\databasebackup\$dbName.bak"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment