I had to setup database mirroring for 50 databases on amazon EC2 servers which are in different availability zones. Mirroring needs to be initiated with a full and at least one transaction log restores. Restoring 50 databases manually is a cumbersome task. Some of these databases have multiple data files and the logical names are different. I initially tried to generate restore scripts using TSQL WHILE or CURSOR but I quickly lost the plot with multiple temp tables and variables. You need to first run a RESTORE HEADERONLY for each database file, get the database name, run RESTORE VERIFYONLY for Logical/physical file names, build restore scripts.
Python seemed perfect tool for the job because you only need to run two commands on SQL Server and the rest of it is manipulating file names, looping through logical files etc. This is a perfect excuse to try Python at work :). I used pyodbc to make connection to database. If you dont have pyodbc module, you might want to install it before trying the script. The script can handle databases with multiple data files. Default target data file/logfile directories can be declared.