• I think you might be able to get this work with SP_MSForEachDB still. I've got a script to get a list of all DBs and any orphaned users in them. To make it easier to read, it includes the name of the DB by saving the DB name as a variable.

    So possibly with your code this:

    EXEC master.sys.sp_MSforeachdb

    N'

    declare @dbname sysname

    set @dbname = ''?''

    INSERT INTO Dba_admin.dbo.databaseDataFileSize

    SELECT @dbname, SUM(size) * 8, cast(getdate() as date), cast(getdate() as time)

    FROM [?].sys.database_files

    WHERE type = 0;'

    might work.