I am migrating over 50 SQL databases in my day job. I'm a poor scripter and for-looper so I did the GUI version of Backup and Restore, selected Script, and threw it in excel to then "for loop." I found that the customer named their logical file names the same for many databases. My Google-fu came up with this and i updated my "script" as needed. Yipee.

SELECT DB_NAME(database_id) AS DatabaseName, name AS LogicalFileName, physical_name AS PhysicalFileName FROM sys.master_files AS mf