Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

How to automatically script-out all objects in database ? Expand / Collapse
Author
Message
Posted Wednesday, January 02, 2013 9:59 AM
SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Yesterday @ 3:40 PM
Points: 258, Visits: 796
Hi all,

I need to automatically script out all objects from a databases similarly like in SSMS context menu in <Database>/Tasks/Generate scripts.

Here is the reason for it: this is development server. I have a job where once a week I run restore from prod backup, but developers usually forget to save their work in TFS. In order to prevent losing their work, I want to script out all the contents of database priorly to restore.

Thanks
Post #1401941
Posted Wednesday, January 02, 2013 10:21 AM


SSC Eights!

SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!

Group: General Forum Members
Last Login: Today @ 12:50 PM
Points: 890, Visits: 1,859
attached is a powershell script I have used to script out all objects. This scripts all objects to their own file you can adjust the $Scripter.Options.FileName option. The script either accepts a text file with a list of servers or if a file is not supplied it will run with the local instance.

Bob
-----------------------------------------------------------------------------
http://www.sqlservercentral.com/articles/Best+Practices/61537/


  Post Attachments 
scripter.txt (36 views, 14.01 KB)
Post #1401953
Posted Wednesday, January 02, 2013 11:28 AM
SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Yesterday @ 3:40 PM
Points: 258, Visits: 796
Thanks a lot Robert.

This is great solution. I did not run it yet, I am not very proficient in Powershell, I will let you know about results.
Post #1401992
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse