Skip to content

Instantly share code, notes, and snippets.

@andrerocker
Created October 30, 2010 22:36
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andrerocker/655819 to your computer and use it in GitHub Desktop.
Save andrerocker/655819 to your computer and use it in GitHub Desktop.
Powershell Script to: Export ONLY the data from yours SQLServer like mysqldump
$database_host = "<host>"
$database_name = "<database>"
$output_file = "<output_file>"
$user = "<username>"
$password = "<password>"
[system.reflection.assembly]::loadWithPartialName('Microsoft.SqlServer.SMO')
$server = new-object "Microsoft.SqlServer.Management.Smo.Server" $database_host
$server.connectionContext.loginSecure = $false
$server.connectionContext.set_Login($user)
$server.connectionContext.set_Password($password)
$database = $server.databases[$database_name]
$scripter = new-object "Microsoft.SqlServer.Management.Smo.Scripter" $server
$scripter.options.fileName = $output_file
$scripter.options.scriptSchema = $false
$scripter.options.scriptData = $true
$scripter.options.toFileOnly = $true
foreach ($s in $scripter.enumScript($database.tables)) { write-host $s }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment