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.
[reflection.assembly]::LoadWithPartialName(“Microsoft.SqlServer.Smo”)
$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
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
Yeah – I agree. That would help.