I know how to programatically find all of the information that you need to script the objects. But to actually script them, you might have to write the script generation code yourself.
If you're writing code to find out all about the existing objects, the term to google for is "SQL Server Data Dictionary".
I'll give you some starting examples.
To find all foreign key constraints on a specific table:
select * from information_schema.table_constraints where CONSTRAINT_TYPE = 'FOREIGN KEY'
and TABLE_NAME = 'aspnet_Roles'
To find all of the foreign key constraints that reference a specific table:
select
sys.foreign_keys.name as key_name,
pt.name as parent_table_name,
pc.name as parent_column_name,
ct.name as referenced_table_name,
cc.name as referenced_colum_name
from sys.foreign_key_columns
inner join sys.foreign_keys on sys.foreign_key_columns.constraint_object_id = sys.foreign_keys.object_id
inner join sys.tables pt on sys.foreign_key_columns.parent_object_id = pt.object_id
inner join sys.tables ct on sys.foreign_key_columns.referenced_object_id = ct.object_id
inner join sys.columns pc on sys.foreign_key_columns.parent_object_id = pc.object_id and sys.foreign_key_columns.parent_column_id = pc.column_id
inner join sys.columns cc on sys.foreign_key_columns.referenced_object_id = cc.object_id and sys.foreign_key_columns.referenced_column_id = cc.Column_id
where ct.name = 'aspnet_Applications'