Sql-server – How to connect to sql server to take backup of a database from powershell

powershellsql server

I am new to powershell. I got requirement to take the backup of MS sql database backup from the other machine and not within the server.

Can you please let me know what possible utilities required to connect and take the full backup.

Best Answer

Make sure you have the sqlps module installed on the machine from which you could be taking the backup. After that you can use the Backup-SqlDatabase cmdlet to backup a certain database.

Example:

Backup-SqlDatabase -ServerInstance 'SERVERNAME\INSTANCE' -Database 'MYDB' -BackupFile 'F:\SQLBackup\mydbbackup.bak'

This would take a full backup. More info on the cmdlet here.