December 2013
Intermediate to advanced
1872 pages
153h 31m
English
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" ...