Using ScriptingOptions with SQLPS

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.

2 thoughts on “Using ScriptingOptions with SQLPS”

  1. 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

Your email address will not be published. Required fields are marked *