The Multifunctioning DBA

Oct 23 2012   5:52PM GMT

PowerShell Table and Index DDL

Colin Smith Colin Smith Profile: Colin Smith


$server = “Instance”
$tables = “Table Name”
connect-sql $server
$db = $s.databases | where {$ -eq “EventManagement_Test”}
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.Script($so) | Out-File $outdir/$table.sql -Append

 Comment on this Post

There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when other members comment.

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

Share this item with your network: