From 1939d1d98c1d5e44f46202a14fb0f721cdc17f9c Mon Sep 17 00:00:00 2001
From: Vlad Drumea <48413726+VladDBA@users.noreply.github.com>
Date: Thu, 26 Dec 2024 18:41:20 +0200
Subject: [PATCH] changes for #288,#292,#293,#294,#295,#296,#285
---
PSBlitz.ps1 | 4062 ++++++++++--------------
README.md | 4 +-
Resources/PSBlitzOutput.xlsx | Bin 707366 -> 710232 bytes
Resources/spBlitzIndex_NonSPLatest.sql | 16 +-
Resources/spBlitzLock_NonSPLatest.sql | 11 +-
5 files changed, 1760 insertions(+), 2333 deletions(-)
diff --git a/PSBlitz.ps1 b/PSBlitz.ps1
index 5548115..c8cd74b 100644
--- a/PSBlitz.ps1
+++ b/PSBlitz.ps1
@@ -272,8 +272,8 @@ param(
###Internal params
#Version
-$Vers = "4.5.1"
-$VersDate = "2024-12-19"
+$Vers = "5.0.0"
+$VersDate = "2024-12-26"
$TwoMonthsFromRelease = [datetime]::ParseExact("$VersDate", 'yyyy-MM-dd', $null).AddMonths(2)
$NowDate = Get-Date
#Get script path
@@ -631,10 +631,10 @@ function Invoke-PSBlitzQuery {
}
$global:StepOutcome = "Success"
if (($StepNameIn -like "sp_BlitzCache*") -or ($StepNameIn -like "sp_BlitzQueryStore*") -or
- ($StepNameIn -eq "sp_BlitzIndex mode 1") -or ($StepNameIn -eq "Stats Info") -or ($StepNameIn -eq "Index Frag Info")) {
+ ($StepNameIn -eq "sp_BlitzIndex mode 1") -or ($StepNameIn -eq "Stats Info") -or ($StepNameIn -eq "Index Frag Info") -or
+ ($StepNameIn -eq "sp_BlitzLock") -or ($StepNameIn -eq "Return sp_BlitzWho") -or ($StepNameIn -eq "Open Transacion Info")) {
$RecordsReturned = $global:PSBlitzSet.Tables[0].Rows.Count
Add-LogRow $StepNameIn $global:StepOutcome "$RecordsReturned records returned"
-
}
elseif ('Stats Info', 'sp_BlitzIndex mode 0', 'sp_BlitzIndex mode 2', 'sp_BlitzIndex mode 4' -contains $StepNameIn) {
$RecordsReturned = $global:PSBlitzSet.Tables[0].Rows.Count
@@ -789,7 +789,7 @@ function Convert-QueryTableToHtml {
$formattedName = if ("current_query", "most_recent_query" -contains $currentColumn) {
"Query"
}
- elseif ("current_sql", "most_recent_sql","query_sql_text" -contains $currentColumn) {
+ elseif ("current_sql", "most_recent_sql", "query_sql_text" -contains $currentColumn) {
"Query Text"
}
elseif ($currentColumn -like "*_*") {
@@ -2107,8 +2107,6 @@ $htmlTable2
[int]$RowsReturned = $AcTranTbl.Rows.Count
if ($RowsReturned -le 0) {
Write-Host " ->No open transactions found."
- $StepOutcome = "No open transactions found"
- Add-LogRow "->Open Transacion Info" $StepOutcome
}
else {
##Exporting execution plans to file
@@ -2143,9 +2141,9 @@ $htmlTable2
$htmlTable1 = Convert-TableToHtml $AcTranTbl -ExclCols "current_sql", "current_plan", "most_recent_sql", "most_recent_plan" -DebugInfo:$DebugInfo -AnchorFromHere -AnchorIDs "Current", "MostRecent"
- $htmlTable2 = Convert-QueryTableToHtml $AcTranTbl -Cols "current_query", "current_sql" -AnchorToHere -AnchorID "Current"
+ $htmlTable2 = Convert-QueryTableToHtml $AcTranTbl -Cols "current_query", "current_sql" -AnchorToHere -AnchorID "Current" -DebugInfo:$DebugInfo
- $htmlTable3 = Convert-QueryTableToHtml $AcTranTbl -Cols "most_recent_query", "most_recent_sql" -AnchorToHere -AnchorID "MostRecent"
+ $htmlTable3 = Convert-QueryTableToHtml $AcTranTbl -Cols "most_recent_query", "most_recent_sql" -AnchorToHere -AnchorID "MostRecent" -DebugInfo:$DebugInfo
$html = $HTMLPre + @"
$tableName
@@ -2465,39 +2463,39 @@ $htmlBlock
##Saving file
Save-ExcelFile $ExcelFile
}
- Invoke-ClearVariables DBInfoTbl, DBFileInfoTbl, PSBlitzSet
+ Invoke-ClearVariables DBInfoTbl, DBFileInfoTbl, PSBlitzSet
}
}
- if ($JobStatus -ne "Running") {
- Invoke-BlitzWho -BlitzWhoQuery $BlitzWhoRepl -IsInLoop N
- $BlitzWhoPass += 1
- }
- #####################################################################################
- # sp_Blitz #
- #####################################################################################
- if ($IsAzureSQLDB) {
- $StepStart = get-date
- $StepEnd = get-date
- Write-Host " Azure SQL DB - skipping instance health."
- Add-LogRow "sp_Blitz" "Skipped" "Azure SQL DB"
+ if ($JobStatus -ne "Running") {
+ Invoke-BlitzWho -BlitzWhoQuery $BlitzWhoRepl -IsInLoop N
+ $BlitzWhoPass += 1
+ }
+ #####################################################################################
+ # sp_Blitz #
+ #####################################################################################
+ if ($IsAzureSQLDB) {
+ $StepStart = get-date
+ $StepEnd = get-date
+ Write-Host " Azure SQL DB - skipping instance health."
+ Add-LogRow "sp_Blitz" "Skipped" "Azure SQL DB"
+ }
+ else {
+ Write-Host " Retrieving instance health data... " -NoNewLine
+ $SqlScriptFilePath = Join-Path -Path $ResourcesPath -ChildPath "spBlitz_NonSPLatest.sql"
+ [string]$Query = [System.IO.File]::ReadAllText("$SqlScriptFilePath")
+ if (($IsIndepth -eq "Y") -and ([string]::IsNullOrEmpty($CheckDB))) {
+ [string]$Query = $Query -replace ";SET @CheckUserDatabaseObjects = 0;", ";SET @CheckUserDatabaseObjects = 1;"
}
- else {
- Write-Host " Retrieving instance health data... " -NoNewLine
- $SqlScriptFilePath = Join-Path -Path $ResourcesPath -ChildPath "spBlitz_NonSPLatest.sql"
- [string]$Query = [System.IO.File]::ReadAllText("$SqlScriptFilePath")
- if (($IsIndepth -eq "Y") -and ([string]::IsNullOrEmpty($CheckDB))) {
- [string]$Query = $Query -replace ";SET @CheckUserDatabaseObjects = 0;", ";SET @CheckUserDatabaseObjects = 1;"
- }
- Invoke-PSBlitzQuery -QueryIn $Query -StepNameIn "sp_Blitz" -ConnStringIn $ConnString -CmdTimeoutIn $DefaultTimeout
- if ($global:StepOutcome -eq "Success") {
- #$BlitzTbl = New-Object System.Data.DataTable
- $BlitzTbl = $global:PSBlitzSet.Tables[0]
+ Invoke-PSBlitzQuery -QueryIn $Query -StepNameIn "sp_Blitz" -ConnStringIn $ConnString -CmdTimeoutIn $DefaultTimeout
+ if ($global:StepOutcome -eq "Success") {
+ #$BlitzTbl = New-Object System.Data.DataTable
+ $BlitzTbl = $global:PSBlitzSet.Tables[0]
- if ($ToHTML -eq "Y") {
- $tableName = "Instance Health"
- $htmlTable = Convert-TableToHtml $BlitzTbl -NoCaseChange -TblID "InstanceHealthTable" -HasURLs -DebugInfo:$DebugInfo
- $html = $HTMLPre + @"
+ if ($ToHTML -eq "Y") {
+ $tableName = "Instance Health"
+ $htmlTable = Convert-TableToHtml $BlitzTbl -NoCaseChange -TblID "InstanceHealthTable" -HasURLs -DebugInfo:$DebugInfo
+ $html = $HTMLPre + @"
$tableName
@@ -2510,48 +2508,48 @@ $JumpToTop
"@
- if ($DebugInfo) {
- Write-Host " ->Writing HTML file." -fore yellow
- }
- $HTMLFilePath = Join-Path -Path $HTMLOutDir -ChildPath "spBlitz.html"
- $html | Out-File -Encoding utf8 -FilePath "$HTMLFilePath"
+ if ($DebugInfo) {
+ Write-Host " ->Writing HTML file." -fore yellow
+ }
+ $HTMLFilePath = Join-Path -Path $HTMLOutDir -ChildPath "spBlitz.html"
+ $html | Out-File -Encoding utf8 -FilePath "$HTMLFilePath"
- }
- else {
- ##Populating the "sp_Blitz" sheet
- $ExcelSheet = $ExcelFile.Worksheets.Item("Instance Health")
- #Specify at which row in the sheet to start adding the data
+ }
+ else {
+ ##Populating the "sp_Blitz" sheet
+ $ExcelSheet = $ExcelFile.Worksheets.Item("Instance Health")
+ #Specify at which row in the sheet to start adding the data
- Convert-TableToExcel $BlitzTbl $ExcelSheet -StartRow $DefaultStartRow -DebugInfo:$DebugInfo -URLCols "URL" -MapURLToColNum 3 -URLTextCol "Finding"
+ Convert-TableToExcel $BlitzTbl $ExcelSheet -StartRow $DefaultStartRow -DebugInfo:$DebugInfo -URLCols "URL" -MapURLToColNum 3 -URLTextCol "Finding"
- ##Saving file
- $ExcelFile.Save()
- }
- ##Cleaning up variables
- Invoke-ClearVariables BlitzTbl, PSBlitzSet
+ ##Saving file
+ $ExcelFile.Save()
}
+ ##Cleaning up variables
+ Invoke-ClearVariables BlitzTbl, PSBlitzSet
}
+ }
- if ($JobStatus -ne "Running") {
- Invoke-BlitzWho -BlitzWhoQuery $BlitzWhoRepl -IsInLoop N
- $BlitzWhoPass += 1
- }
+ if ($JobStatus -ne "Running") {
+ Invoke-BlitzWho -BlitzWhoQuery $BlitzWhoRepl -IsInLoop N
+ $BlitzWhoPass += 1
+ }
- #####################################################################################
- # sp_BlitzFirst 30 seconds #
- #####################################################################################
- Write-Host " What's happening in a 30 seconds time-frame... " -NoNewLine
- $SqlScriptFilePath = Join-Path -Path $ResourcesPath -ChildPath "spBlitzFirst_NonSPLatest.sql"
- [string]$Query = [System.IO.File]::ReadAllText("$SqlScriptFilePath")
- Invoke-PSBlitzQuery -QueryIn $Query -StepNameIn "sp_BlitzFirst 30 seconds" -ConnStringIn $ConnString -CmdTimeoutIn $DefaultTimeout
- if ($global:StepOutcome -eq "Success") {
- $BlitzFirstTbl = $global:PSBlitzSet.Tables[0]
+ #####################################################################################
+ # sp_BlitzFirst 30 seconds #
+ #####################################################################################
+ Write-Host " What's happening in a 30 seconds time-frame... " -NoNewLine
+ $SqlScriptFilePath = Join-Path -Path $ResourcesPath -ChildPath "spBlitzFirst_NonSPLatest.sql"
+ [string]$Query = [System.IO.File]::ReadAllText("$SqlScriptFilePath")
+ Invoke-PSBlitzQuery -QueryIn $Query -StepNameIn "sp_BlitzFirst 30 seconds" -ConnStringIn $ConnString -CmdTimeoutIn $DefaultTimeout
+ if ($global:StepOutcome -eq "Success") {
+ $BlitzFirstTbl = $global:PSBlitzSet.Tables[0]
- if ($ToHTML -eq "Y") {
- $htmlTable = Convert-TableToHtml $BlitzFirstTbl -NoCaseChange -HasURLs -DebugInfo:$DebugInfo
- $HtmlTabName = "What's happening on the instance now?"
- $html = $HTMLPre + @"
+ if ($ToHTML -eq "Y") {
+ $htmlTable = Convert-TableToHtml $BlitzFirstTbl -NoCaseChange -HasURLs -DebugInfo:$DebugInfo
+ $HtmlTabName = "What's happening on the instance now?"
+ $html = $HTMLPre + @"
$HtmlTabName
@@ -2562,48 +2560,48 @@ $htmlTable
"@
- if ($DebugInfo) {
- Write-Host " ->Writing HTML file." -fore yellow
- }
- $HTMLFilePath = Join-Path -Path $HTMLOutDir -ChildPath "BlitzFirst30s.html"
- $html | Out-File -Encoding utf8 -FilePath "$HTMLFilePath"
- }
- else {
-
- ##Populating the "sp_BlitzFirst 30s" sheet
- $ExcelSheet = $ExcelFile.Worksheets.Item("Happening Now")
- Convert-TableToExcel $BlitzFirstTbl $ExcelSheet -StartRow $DefaultStartRow -DebugInfo:$DebugInfo -URLCols "URL" -MapURLToColNum 3 -URLTextCol "Finding"
- ##Saving file
- Save-ExcelFile $ExcelFile
- }
- Invoke-ClearVariables BlitzFirstTbl, PSBlitzSet
+ if ($DebugInfo) {
+ Write-Host " ->Writing HTML file." -fore yellow
+ }
+ $HTMLFilePath = Join-Path -Path $HTMLOutDir -ChildPath "BlitzFirst30s.html"
+ $html | Out-File -Encoding utf8 -FilePath "$HTMLFilePath"
}
- if ($JobStatus -ne "Running") {
- Invoke-BlitzWho -BlitzWhoQuery $BlitzWhoRepl -IsInLoop N
- $BlitzWhoPass += 1
+ else {
+
+ ##Populating the "sp_BlitzFirst 30s" sheet
+ $ExcelSheet = $ExcelFile.Worksheets.Item("Happening Now")
+ Convert-TableToExcel $BlitzFirstTbl $ExcelSheet -StartRow $DefaultStartRow -DebugInfo:$DebugInfo -URLCols "URL" -MapURLToColNum 3 -URLTextCol "Finding"
+ ##Saving file
+ Save-ExcelFile $ExcelFile
}
+ Invoke-ClearVariables BlitzFirstTbl, PSBlitzSet
+ }
+ if ($JobStatus -ne "Running") {
+ Invoke-BlitzWho -BlitzWhoQuery $BlitzWhoRepl -IsInLoop N
+ $BlitzWhoPass += 1
+ }
- #####################################################################################
- # sp_BlitzFirst since startup #
- #####################################################################################
- if ($IsIndepth -eq "Y") {
- Write-Host " Retrieving waits recorded since instance startup... " -NoNewLine
- $SqlScriptFilePath = Join-Path -Path $ResourcesPath -ChildPath "spBlitzFirst_NonSPLatest.sql"
- [string]$Query = [System.IO.File]::ReadAllText("$SqlScriptFilePath")
- [string]$Query = $Query -replace ";SET @SinceStartup = 0;", ";SET @SinceStartup = 1;"
- Invoke-PSBlitzQuery -QueryIn $Query -StepNameIn "sp_BlitzFirst since startup" -ConnStringIn $ConnString -CmdTimeoutIn $DefaultTimeout
- if ($global:StepOutcome -eq "Success") {
- $WaitsTbl = $global:PSBlitzSet.Tables[0]
- $StorageTbl = $global:PSBlitzSet.Tables[1]
- $PerfmonTbl = $global:PSBlitzSet.Tables[2]
+ #####################################################################################
+ # sp_BlitzFirst since startup #
+ #####################################################################################
+ if ($IsIndepth -eq "Y") {
+ Write-Host " Retrieving waits recorded since instance startup... " -NoNewLine
+ $SqlScriptFilePath = Join-Path -Path $ResourcesPath -ChildPath "spBlitzFirst_NonSPLatest.sql"
+ [string]$Query = [System.IO.File]::ReadAllText("$SqlScriptFilePath")
+ [string]$Query = $Query -replace ";SET @SinceStartup = 0;", ";SET @SinceStartup = 1;"
+ Invoke-PSBlitzQuery -QueryIn $Query -StepNameIn "sp_BlitzFirst since startup" -ConnStringIn $ConnString -CmdTimeoutIn $DefaultTimeout
+ if ($global:StepOutcome -eq "Success") {
+ $WaitsTbl = $global:PSBlitzSet.Tables[0]
+ $StorageTbl = $global:PSBlitzSet.Tables[1]
+ $PerfmonTbl = $global:PSBlitzSet.Tables[2]
- if ($ToHTML -eq "Y") {
- #Waits
- $HtmlTabName = "Wait Stats Since Last Startup"
+ if ($ToHTML -eq "Y") {
+ #Waits
+ $HtmlTabName = "Wait Stats Since Last Startup"
- $htmlTable = Convert-TableToHtml $WaitsTbl -NoCaseChange -HasURLs -CSSClass "WaitStats" -DebugInfo:$DebugInfo
+ $htmlTable = Convert-TableToHtml $WaitsTbl -NoCaseChange -HasURLs -CSSClass "WaitStats" -DebugInfo:$DebugInfo
- $html = $HTMLPre + @"
+ $html = $HTMLPre + @"
$HtmlTabName
@@ -2613,19 +2611,19 @@ $JumpToTop