O'Reilly logo

Microsoft® SQL Server 2012 Unleashed by Alex T. Silverstein, Chris Gallelli, Paul T. Bertucci, Ray Rankins

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Performing a Database Backup

Another example that may be useful is performing a database backup using SMO from the PowerShell 2.0 console. The easiest way to load the SMO assemblies that will be used to perform the backups is to use the Import-Module cmdlet to import the SQLPS module. The module loads and registers the SQL Server snap-ins and manageability assemblies. Using the AdventureWorks2012 database, you can back up the database using just a few lines:

Import-Module "SQLPS" -DisableNameChecking$server=New-Object Microsoft.SqlServer.Management.Smo.Server$backup=new-object Microsoft.SqlServer.Management.Smo.Backup$file=new-object Microsoft.SqlServer.Management.Smo.BackupDeviceItem$file.Name="C:\backup\AW_DB.bak" ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required