The Multifunctioning DBA

Oct 23 2012   5:52PM GMT

PowerShell Table and Index DDL



Posted by: Colin Smith
Database

sqlscript-options

$server = “Instance”
$tables = “Table Name”
connect-sql $server
$db = $s.databases | where {$_.name -eq “EventManagement_Test”}
$db.name
foreach ($table in $tables)
{
$outdir = “C:\ddl\$server”
if (!(Test-Path $outdir))
{
New-Item -ItemType container $outdir
}
$tbl = $db.Tables | where {$_.Name -eq $table}
$name = $tbl.name

$tbl.Script($so) | Out-File $outdir/$table.sql -Append
}

Comment on this Post

Leave a comment: