Someone dropped this reply in a sql forum. It works very well with the low level read access I had but, I think because of the way it output its results, I couldn't ingest it using the DB Connector. I had to get the DBA to write a script that wrote the output to a csv file which I sucked in with the UF.
Here it is anyway:
exec sp_msforeachdb '
declare @pages bigint -- Working variable for size calc.
,@dbname sysname
,@dbsize bigint
,@logsize bigint
,@reservedpages bigint
,@usedpages bigint
,@rowCount bigint
select @dbsize = sum(size)
from [?].sys.database_files
where type = 0
select @logsize = sum(size)
from [?].sys.database_files
where type = 1
select @reservedpages = sum(a.total_pages),
@usedpages = sum(a.used_pages),
@pages = sum(
CASE
-- XML-Index and FT-Index internal tables are not considered "data", but is part of "index_size"
When it.internal_type IN (202,204,211,212,213,214,215,216) Then 0
When a.type <> 1 Then a.used_pages
When p.index_id < 2 Then a.data_pages
Else 0
END
)
from [?].sys.partitions p
join [?].sys.allocation_units a
on p.partition_id = a.container_id
left join [?].sys.internal_tables it
on p.object_id = it.object_id
select ''?'' as databasename,
@dbsize/128 as database_size_MB,
@logsize/128 as log_size_MB,
(case when @dbsize >= @reservedpages then (@dbsize-@reservedpages) /128 else 0 end) as unallocated_space_MB,
reserved_MB = @reservedpages / 128 ,
data_MB = @pages / 128 ,
index_size_MB = (@usedpages - @pages) / 12,
unused_MB = (@reservedpages - @usedpages) / 128
... View more