SQL-Instance-Backup/SQL-Instance-Backup.ps1
2025-03-14 11:14:15 -06:00

11 lines
448 B
PowerShell

# 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
}