You can run sp_blitz (First Responder Kit by Brent Ozar) on a sql server to output to a table. But it will store the output only on that server. I am using Dbatools.io PowerShell commands currently. I can run the sp_Blitz commands agains all SQL servers. But I don’t know how to capture the output on my report server in a single database table centrally. Is there a way to store output of sp_blitz command against a list of all servers so that I can create a report for all critical issues across all my servers? Here is the code I am using.
Import-Module dbatools
Set your database connection details
$database = "<Database Name>"
$table = "<table name containing server names>"
$output = "dbo.BlitzResults"
$sqlInstance = "<InstanceName>" # The instance where the ServerList table is located
$servers = Invoke-DbaQuery -SqlInstance $sqlInstance -Database $database -Query "select * from $table;"
$servers
Loop through each server and execute sp_Blitz
foreach ($server in $servers.ItemArray) {
Write-Host "Running sp_Blitz on $($server)"
try {
$result = Invoke-DbaQuery -SqlInstance $server -Database master -Query "EXEC dbo.sp_Blitz"
# Output the results
$result | Format-Table -AutoSize
#Following two lines are not working as expected
#Write-Host $result.ItemArray
#Write-DbaDbTableData -SqlInstance $sqlInstance -DestinationDatabase $database -DestinationTable $output -Data $result.ItemArray -CreateTable $true
} catch {
Write-Host "Failed to run sp_Blitz on $($server.ServerName). Error: $_"
}
}