Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $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]
- $database.script() | out-file $output_file
- $scripter = new-object "Microsoft.SqlServer.Management.Smo.Scripter" $server
- $scripter.options.appendToFile = $false
- $scripter.options.scriptData = $true
- $scripter.options.includeIfNotExists = $true
- $scripter.options.includeHeaders = $true
- $scripter.options.indexes = $true
- $scripter.options.withDependencies = $true
- $scripter.options.toFileOnly = $true
- $scripter.options.fileName = $output_file
- $tables = $database.tables
- foreach ($s in $scripter.enumScript($tables)) { write-host $s }
Add Comment
Please, Sign In to add comment