Using ScriptingOptions with SQLPS

March 4, 2008

I’ve written before that SQL Server 2008 (February CTP) gives you SQLPS – a PowerShell interface to SQL Server.

So I was trying to get the ScriptingOptions happening, and this is the only way I’ve found so far. It’s ugly, and if you have a better way of doing this, please post a comment for me.

$so = New-Object Microsoft.SqlServer.Management.Smo.ScriptingOptions
$so.DriAllConstraints = $true
(get-item Sales.Store).Script($so)

And this gives me the Sales.Store table with all the default constraints thrown in. Much better. Ugly way of doing it, but at least it works.

This Post Has 2 Comments

  1. Darren Gosbell

    Rob, I just tried this without the first reflection line and it still works. Which means that the assembly is loaded, but we need to get the equivalent of a “using” statement so that we can just do the following:

    $so = new-object ScriptingOptions

Leave a Reply

LobsterPot Blogs

Blog posts by Rob Farley and other LobsterPot Solutions team members.


Related Blogs