Skip to content

Commit c9a4139

Browse files
authored
Merge pull request #25 from microsoft/ReleaseV6.25.04.25
Release v6.25.04.25
2 parents 13b9575 + fe381d2 commit c9a4139

30 files changed

Lines changed: 3864 additions & 6332 deletions

README.md

Lines changed: 319 additions & 150 deletions
Large diffs are not rendered by default.

SQL LogScout/Bin/CleanupIncompleteShutdown.ps1

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ function HandleCatchBlockCleanup ([string] $function_name, [System.Management.Au
4747

4848
function Initialize-CleanupIncompleteShutdownTaskLog
4949
(
50-
[string]$LogFilePath = $env:TEMP,
50+
[string]$LogFilePath,
5151
[string]$LogFileName = "##SQLLogScout_CleanupIncompleteShutdown"
5252
)
5353
{
@@ -59,11 +59,15 @@ function Initialize-CleanupIncompleteShutdownTaskLog
5959
#>
6060
try
6161
{
62+
#Create log file in temp directory using full path. The temp var can come back as 8.3 format and so ensure we have the full path.
63+
$shortEnvTempPath = $env:TEMP
64+
$LogFilePath = (Get-Item $shortEnvTempPath).FullName
65+
6266
#Cache LogFileName without date so we can delete old records properly
6367
$LogFileNameStringToDelete = $LogFileName
6468

6569
#update file with date
66-
$LogFileName = ($LogFileName -replace "$LogFileName", ($LogFileName+"_" + @(Get-Date -Format "yyyyMMddTHHmmssffff") + ".log"))
70+
$LogFileName = $LogFileName + "_" + (Get-Date -Format "yyyyMMddTHHmmssffff") + ".log"
6771
$global:CleanupIncompleteShutdownLog = $LogFilePath + '\' + $LogFileName
6872
New-Item -ItemType "file" -Path $global:CleanupIncompleteShutdownLog -Force | Out-Null
6973
Write-Host "Created log file $global:CleanupIncompleteShutdownLog"
@@ -205,7 +209,7 @@ Log-CleanupIncompleteShutdownTask "=============================================
205209

206210
if ([string]::IsNullOrWhiteSpace($ServerName))
207211
{
208-
Select-SQLServerForDiagnostics
212+
Select-SQLServerForDiagnostics | Out-Null
209213
}
210214
else
211215
{
@@ -219,7 +223,7 @@ $xevent_alwayson_session = "SQLLogScout_AlwaysOn_Data_Movement"
219223

220224
try
221225
{
222-
Log-CleanupIncompleteShutdownTask "Testing connection into: '$global:sql_instance_conn_str'. If connection fails, verify instance name." -WriteToConsole $true
226+
Log-CleanupIncompleteShutdownTask "Testing connection into: '$global:sql_instance_conn_str'. If connection fails, verify instance name or running status." -WriteToConsole $true
223227
$ConnectionResult = Test-SQLConnection ($global:sql_instance_conn_str)
224228

225229
if ($ConnectionResult -eq $false)
@@ -282,18 +286,12 @@ try
282286
Start-Process -FilePath $executable -ArgumentList $argument_list -WindowStyle Hidden
283287

284288
#stop perf Xevent
285-
Log-CleanupIncompleteShutdownTask "Executing 'Stop_SQLLogScout_Xevent' session. It will stop the SQLLogScout performance Xevent trace in case it was found to be running..." -WriteToConsole $true
286-
$query = "IF HAS_PERMS_BY_NAME(NULL, NULL, 'ALTER ANY EVENT SESSION') = 1 BEGIN ALTER EVENT SESSION [$xevent_session] ON SERVER STATE = STOP; DROP EVENT SESSION [$xevent_session] ON SERVER; END"
287-
$executable = "sqlcmd.exe"
288-
$argument_list = "-S" + $server + " -E -w8000 -Q`"" + $query + "`""
289-
Start-Process -FilePath $executable -ArgumentList $argument_list -WindowStyle Hidden
289+
Log-CleanupIncompleteShutdownTask "Executing 'Stop_$xevent_session' session. It will stop the SQLLogScout performance Xevent trace in case it was found to be running..." -WriteToConsole $true
290290

291-
292-
$query = "IF HAS_PERMS_BY_NAME(NULL, NULL, 'ALTER ANY EVENT SESSION') = 1 BEGIN ALTER EVENT SESSION [$xevent_alwayson_session] ON SERVER STATE = STOP; DROP EVENT SESSION [$xevent_alwayson_session] ON SERVER; END"
291+
$query = "IF HAS_PERMS_BY_NAME(NULL, NULL, 'ALTER ANY EVENT SESSION') = 1 BEGIN ALTER EVENT SESSION [$xevent_session] ON SERVER STATE = STOP; DROP EVENT SESSION [$xevent_session] ON SERVER; END"
293292
$executable = "sqlcmd.exe"
294-
$argument_list = "-S" + $server + " -E -w8000 -Q`"" + $query + "`""
293+
$argument_list = "-S" + $global:sql_instance_conn_str + " -E -w8000 -Q`"" + $query + "`""
295294
Start-Process -FilePath $executable -ArgumentList $argument_list -WindowStyle Hidden
296-
297295

298296
$xevent_session = "xevent_SQLLogScout"
299297
$query = "ALTER EVENT SESSION [$xevent_session] ON SERVER STATE = STOP; DROP EVENT SESSION [$xevent_session] ON SERVER;"
@@ -302,9 +300,14 @@ try
302300
Start-Process -FilePath $executable -ArgumentList $argument_list -WindowStyle Hidden
303301

304302
#stop always on data movement Xevent
305-
Log-CleanupIncompleteShutdownTask "Executing 'Stop_SQLLogScout_AlwaysOn_Data_Movement'. It will stop the SQLLogScout AlwaysOn Xevent trace in case it was found to be running..." -WriteToConsole $true
306-
$xevent_session = "SQLLogScout_AlwaysOn_Data_Movement"
307-
$query = "ALTER EVENT SESSION [$xevent_session] ON SERVER STATE = STOP; DROP EVENT SESSION [$xevent_session] ON SERVER;"
303+
Log-CleanupIncompleteShutdownTask "Executing 'Stop_$xevent_alwayson_session'. It will stop the SQLLogScout AlwaysOn Xevent trace in case it was found to be running..." -WriteToConsole $true
304+
305+
$query = "IF HAS_PERMS_BY_NAME(NULL, NULL, 'ALTER ANY EVENT SESSION') = 1 BEGIN ALTER EVENT SESSION [$xevent_alwayson_session] ON SERVER STATE = STOP; DROP EVENT SESSION [$xevent_alwayson_session] ON SERVER; END"
306+
$executable = "sqlcmd.exe"
307+
$argument_list = "-S" + $global:sql_instance_conn_str + " -E -w8000 -Q`"" + $query + "`""
308+
Start-Process -FilePath $executable -ArgumentList $argument_list -WindowStyle Hidden
309+
310+
$query = "ALTER EVENT SESSION [$xevent_alwayson_session] ON SERVER STATE = STOP; DROP EVENT SESSION [$xevent_alwayson_session] ON SERVER;"
308311
$executable = "sqlcmd.exe"
309312
$argument_list ="-S" + $global:sql_instance_conn_str + " -E -w8000 -Q`""+ $query + "`" "
310313
Start-Process -FilePath $executable -ArgumentList $argument_list -WindowStyle Hidden

0 commit comments

Comments
 (0)