SQLPS provide very powerful method that can get the DDL out of database object very easily.
From SQLPS
(get-item TestDB ).script()
From SMO
$server = 'SGC3,8001'
[System.Reflection.Assembly]::LoadwithPartialName("Microsoft.sqlserver.smo");
$conn = New-Object Microsoft.sqlserver.management.smo.server "$server"
$conn
$conn.Databases['TestDB'].script()
This is going to be very useful, if I want to get all the DDL for all tables
Get-ChildItem .\Tables | %{$_.script()} |more
Very useful .
0 comments:
Post a Comment