Skip to content

Instantly share code, notes, and snippets.

@MasayukiOzawa
Last active August 26, 2015 03:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MasayukiOzawa/bc7ca70c89e272dd4330 to your computer and use it in GitHub Desktop.
Save MasayukiOzawa/bc7ca70c89e272dd4330 to your computer and use it in GitHub Desktop.
[Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.Smo") | Out-Null
$Server = "hogehoge"
$Login = "hogehoge"
$Password = "hogehoge"
$DBName = "hogehoge"
$TableName = "hogehoge"
$SQLServer = New-Object Microsoft.SqlServer.Management.Smo.Server($Server)
$SQLServer.ConnectionContext.LoginSecure = $false
$SQLServer.ConnectionContext.Login = $Login
$SQLServer.ConnectionContext.Password = $Password
$DB = $SQLServer.Databases[$DBName]
$Scripter = New-Object Microsoft.SqlServer.Management.Smo.Scripter($SQLServer)
$Scripter.Options.ScriptSchema = $false
$Scripter.Options.ScriptDrops = $false
$Scripter.Options.ScriptData = $true
$Scripter.EnumScript($DB.Tables[$TableName])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment