Summary: Use Windows PowerShell to back up system databases.
How can I use Windows PowerShell to dynamically back up all of the system databases on my servers?
Combining provider lookups with the Backup-SqlDatabase cmdlet makes this simple:
$instances = @(‘KIRK’,’SPOCK’,’PICARD’,’RIKER’)
foreach($instance in $instances){
$dbs = Get-ChildItem SQLSERVER:\SQL\$instance\DEFAULT\Databases -Force |
Where-Object {$_.IsSystemObject -eq $true -and $_.Name -ne 'TempDB'}
$dbs |
ForEach-Object {
Backup-SqlDatabase -ServerInstance $instance -Database $_.Name -BackupFile "C:\DBFiles\$($_.Name).bak" -Initialize }}
$instances |
ForEach-Object {Invoke-Command -ComputerName $_ -ScriptBlock {Get-ChildItem C:\DBFiles\*.bak}}