How do you generate a build script for all views I would like to create a build script that can run through and recreate all views (and stored procedures too, but one step at a time).

I am trying to create a baseline of all of our user databases (around 50 of them) for our developers to run on their local machines, basically recreate all of the databases from the ground up. I have gotten past all the preliminary steps of recreating all dbs, schemas, roles, tables, indexes, constraints,...yada yada. I have relied heavily on the sp_foreachdb function and it works like a charm. Now I am stuck on stored scripts, like views and procs mostly due to the length of some of the scripts.

Reason I need to recreate the entire database setup is because people are dumb and left cross database joins and dependencies in legacy products for us. (yay!) So how can we expect our developers to pull the database down to their local machines for development and testing if first they need stuff from 3-4 other databases. And it doesn't end there, those databases depend on other things to exist. Ugh, circular dependencies.

If I only had one database I would hook up my handy dandy RedGate tool SQLCompare and pull the stuff into a script that they could run. Problem is the number of user databases we have and the desire to automate it.

If anyone can offer some advice that could help me recreate ALL script objects on ALL Databases, I would gladly accept it. The thought of manually scripting out a single database's scripts 50+ times is daunting to say the least. What am I not thinking of?

Thanks Friends!
Among other things, have a look at the object_definition() function and the sys.objects catalog view. See them in action here. 

But yea... you should probably just use your SQLCompare tool, most RedGate tooling is the gold standard for the functionality if you've got access to it.