From 09ad9fe7254bff7c3cc68360dcc95a11b6b8f38b Mon Sep 17 00:00:00 2001 From: Tyler Hale Date: Fri, 14 Mar 2025 11:14:15 -0600 Subject: [PATCH] Initial commit --- SQL-Instance-Backup.ps1 | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 SQL-Instance-Backup.ps1 diff --git a/SQL-Instance-Backup.ps1 b/SQL-Instance-Backup.ps1 new file mode 100644 index 0000000..98c8ca6 --- /dev/null +++ b/SQL-Instance-Backup.ps1 @@ -0,0 +1,11 @@ +# Sql Instance Backup + +$BackupRootPath = "E:\Backup" +$SqlServerInstance = "SQL-SERVER\INSTANCE" + +$Dbs = Invoke-Sqlcmd -ServerInstance $SqlServerInstance -Query "SELECT name,database_id FROM sys.databases" -TrustServerCertificate +foreach ($Db in $Dbs) { + $BackupQuery = "BACKUP DATABASE [$($Db.name)] to DISK = '$BackupRootPath\$($Db.name).bak'" + Invoke-Sqlcmd -ServerInstance $SqlServerInstance -Query $BackupQuery -TrustServerCertificate +} +