What might be a better way to do it is using the Object Explorer Details window in Management Studio. If you click on the Databases folder in Object Explorer, then from the top menu bar select View\Object Explorer Details, then a new tab pops up in SSMS. You can highlight all the databases you want to script, then right click and select Script Database As... Create To...
This will be much more detailed than trying to just use sys.databases and sys.master_files