Performing a Database Backup
Another example that may be useful is performing a database backup using SMO. Using the AdventureWorks2008R2
database, you can back up the database using just a few lines:
The preceding code could be copied into a .ps1
file (for this example, assume it’s copied to c:\temp\backup.ps1
), and it could be changed to accept two arguments. The preceding code could be modified to the following code snippet so that it accepts parameters from the command line:
The changes in the preceding example introduce a new keyword, throw ...
Get Microsoft® SQL Server 2008 R2 Unleashed now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.