Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to be able to dump a database schema to a sql text file using Powershell. I want this because our DBAs want to be able to do a diff on the file that is committed to SVN. They won't execute it if they can't see what it contains.

I've found many scripts that backup to a binary .bak file, but I can't find any that dump as a sql text file.

How do you do this in Powershell?

share|improve this question
This looks like what you're looking for:… – Thomas Stringer Dec 26 '12 at 19:08
What are you looking to dump? Data, schema, objects? Yes, no, all? – billinkc Dec 27 '12 at 18:10
@billinkc I would like to dump all but the data. – user16527 Dec 28 '12 at 17:53
In essence, you'd like to mimic the functionality that is available through SSMS wherein you right-click on a databases, Tasks, Generate Scripts and then script all? It would seem the linked article by @sqlvariant/aaron nelson's is exactly what you're looking for. Is there something it does that doesn't satisfy your needs? – billinkc Dec 28 '12 at 17:57

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.