Sql-server – Database Files through Linked Servers

linked-serversql server 2014

Is there another way to create a script that I can see all database files with their disk space details across databases and across servers?

I can do it through Registered Servers.

But I want to know if I can do it using 1 instance with linked servers for all the servers. My idea is to generate a script that will read each database for each linked server then when I have all the data, it can now be passed to the SQL Server Job.

Thanks.

Best Answer

Powershell is the way. And it make it easier, just install dbatools on one of your admin servers and use get-dbadiskspace

Get-DbaDiskSpace -ComputerName server1, server2, server3 -Unit GB

if you have list of servers then you can use

$servers = get-content "D:\serverlist.txt"
foreach ($server in $servers) {
  Get-DbaDiskSpace -ComputerName $server -Unit GB
}

You can even dump the above info using invoke-sqlcmd2 into a central db for reporting .