How can I use Invoke-SqlCmd with variables to output the SQL command only or some similar method?
I don't think invoke-sqlcmd can do thi.  Regular sqlcmd.exe has the -e parameter to output the batches, although it will not output the "GO"
.  EG

sqlcmd -e -i restore.sql -v database="foo" databaseBak="bk" &gt; Restore.final.sql


You can put SET NOEXEC ON at the top, or just point it at an dummy instance to generate the script.

Or something like:

sqlcmd -e -Q "set noexec on;`n:r restore.sql" -v database="foo" databaseBak="bk"