Note that there is a typo in step three. Drop the last ' mark.
A couple of things. This isn't general purpose, the only reason it works is because there aren't any spaces in any of the tables or the DB name. Second thing, I intentionally went into the wrong DB and ran the code. Yep, got the wrong tables listed. Thought I could just exec ('use '+@DB_nme) but the scope wasn't long enough. This will generate the script for any DB. I haven't fixed all possible errors for data entry on @DB_nme.
declare @DB_nme sysname
set @DB_nme = ' pubs '
set NOCOUNT ON
declare @sql nvarchar(500)
if (CHARINDEX('[',@DB_nme, 0) = 0) set @DB_nme = '[' + rtrim(ltrim(@DB_nme)) + ']'
set @sql = 'use ' + @DB_nme + '
print ''set NOCOUNT ON''
select ''select count(*) as ['' + table_name + ''] from '+ @DB_nme
+ '.dbo.['' + table_name + '']'' from INFORMATION_SCHEMA.TABLES'
exec sp_executesql @sql