Skip to content

Instantly share code, notes, and snippets.

@brazilnut2000
Created April 11, 2018 18:35
Show Gist options
  • Save brazilnut2000/ea676998144067540033914e6e1ba9a2 to your computer and use it in GitHub Desktop.
Save brazilnut2000/ea676998144067540033914e6e1ba9a2 to your computer and use it in GitHub Desktop.
Backup SQL Server Database with Powershell
# Install SQL Server PowerShell module
# https://docs.microsoft.com/en-us/sql/powershell/download-sql-server-ps-module
Install-Module -Name SqlServer
# Backing Up SQL Server Databases is Easier in PowerShell than T-SQL
# http://www.sqlservercentral.com/articles/PowerShell/151510/
Get-SqlDatabase -ServerInstance [SERVERNAME]\SQLEXPRESS |
Where { $_.Name -eq '[DATABASENAME]' } |
Backup-SqlDatabase -BackupFile "c:\temp\[FILE PREFIX]$(Get-Date -UFormat %Y%m%d_%H%M).bak" -Script
# Remove -Script to actually execute the backup, keep it to see the command that will be generated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment