May 2010
Intermediate to advanced
815 pages
21h 55m
English
One of the great new features in SQL Server 2008 is the PowerShell extension that interacts with the SQL Server. In order to create a database in PowerShell, you'll first need to create a PowerShell script that you can call. Listing 8.2 provides just such a script for you.
Listing 8.2: The CreateDB.ps1 script code
# Get the command line options passed to the script Param($dbInstance, $dbName) [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.Smo") $dbServer = new-object Microsoft.SqlServer.Management.Smo.Server ($dbInstance) $db = new-object Microsoft.SqlServer.Management.Smo.Database "Now creating database $dbName..." $db = new-object Microsoft.SqlServer.Management.Smo.Database ($dbServer, ...Read now
Unlock full access