Skip to content

Commit a0ada11

Browse files
authored
Merge pull request #19 from microsoft/v6.24.10.10
Release v6.24.10.10
2 parents ac483ee + 4136b09 commit a0ada11

60 files changed

Lines changed: 13157 additions & 9112 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

SQL LogScout/Bin/AlwaysOnDiagScript.sql

Lines changed: 0 additions & 422 deletions
This file was deleted.

SQL LogScout/Bin/CleanupIncompleteShutdown.ps1

Lines changed: 244 additions & 33 deletions
Large diffs are not rendered by default.

SQL LogScout/Bin/CommonFunctions.psm1

Lines changed: 321 additions & 120 deletions
Large diffs are not rendered by default.

SQL LogScout/Bin/Confirm-FileAttributes.psm1

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -24,30 +24,7 @@ function Confirm-FileAttributes
2424
$parentdir = (Get-Item (Get-Location)).Parent.FullName
2525

2626
$expectedFileAttributes = @(
27-
[PSCustomObject]@{Algorithm = "SHA512"; Hash = "76DBE5D92A6ADBBAD8D7DCAAC5BD582DF5E87D6B7899882BB0D7489C557352219795106EBD3014BC76E07332FA899CE1B58B273AE5836B34653D4C545BBF89A4"; FileName = $pwdir + "\AlwaysOnDiagScript.sql"; FileSize = 21298}
28-
,[PSCustomObject]@{Algorithm = "SHA512"; Hash = "4E2E0C0018B1AE4E6402D5D985B71E03E8AECBB9DA3145E63758343AEAC234E3D4988739CCE1AC034DDA7CE77482B27FB5C2A7A4E266E9C283F90593A1B562A2"; FileName = $pwdir + "\ChangeDataCapture.sql"; FileSize = 4672}
29-
,[PSCustomObject]@{Algorithm = "SHA512"; Hash = "073C0BBAB692A88387AF355A0CEC7A069B7F6C442A8DABF4EFC46E54ACEC7B569B866778A66FE1ADEBF8AD4F30EF3EAF7EF32DD436BC023CD4BC3AD52923AB9F"; FileName = $pwdir + "\Change_Tracking.sql"; FileSize = 5110}
30-
,[PSCustomObject]@{Algorithm = "SHA512"; Hash = "7E4BF16CD162F767D92AB5EE2FCBC0107DB43068A9EA45C68C2E1DD078C1FA15E9A10CEB63B9D8AEA237F4A2D96E7E5CE34AC30C2CEF304056D9FB287DF67971"; FileName = $pwdir + "\HighCPU_perfstats.sql"; FileSize = 6649}
31-
,[PSCustomObject]@{Algorithm = "SHA512"; Hash = "D9FA1C31F90188779B00552755059A0E3747F768AA55DEBE702D039D7F942F7C4EA746EE7DE7AC02D0685DDFEED22854EB85B3268594D0A18F1147CA9C20D55A"; FileName = $pwdir + "\High_IO_Perfstats.sql"; FileSize = 9554}
32-
,[PSCustomObject]@{Algorithm = "SHA512"; Hash = "824A41667D5DAA02729BB469E97701A41A09462EBBEDD2F5851061DC25465DC4422AD52DEDE1B5321FB55D485FDA6DBEE3B6429B303361078ACE3EF0581A8230"; FileName = $pwdir + "\linked_server_config.sql"; FileSize = 1184}
33-
,[PSCustomObject]@{Algorithm = "SHA512"; Hash = "B97914C0D8B53261A6C9CE93D6E306FE36A97FCE2F632C76FB180F2D1A2EC12510095CE35413D349386FD96B0F8EE54256EEE0AD9DA43CB0D386205D63F7EB20"; FileName = $pwdir + "\MiscDiagInfo.sql"; FileSize = 17791}
34-
,[PSCustomObject]@{Algorithm = "SHA512"; Hash = "218F71ECDA1075B4D2B5785A94EF43569306BBDB026C163DFEAF33F960F802D13C65F1BC103CC2978F497A2EF5EA972EE89940C807188FC7366E11A1C30DB2D9"; FileName = $pwdir + "\MSDiagProcs.sql"; FileSize = 194123}
35-
,[PSCustomObject]@{Algorithm = "SHA512"; Hash = "9789564CA007738B53D6CE21E6065A3D57D3E5A85DE85D32EC1456ED5A79CB1FA0265351FE402D266D6E90E31761DCED208AAA98EDA8BBC24AC25CF7819287D5"; FileName = $pwdir + "\QueryStore.sql"; FileSize = 4870}
36-
,[PSCustomObject]@{Algorithm = "SHA512"; Hash = "7216F9591ECB3C38BD962C146E57800687244B1C0E8450157E21CF5922BBBF92BB8431A814E0F5DF68933623DD76F9E4486A5D20162F58C232B8116920C252C7"; FileName = $pwdir + "\ProfilerTraces.sql"; FileSize = 3601}
37-
,[PSCustomObject]@{Algorithm = "SHA512"; Hash = "42BE545BC8D902A9D43146ACFC8D6A164242B567996C992D57CFBC6660B4E08051E7E687E2D140DAE5B17A8EEE652CFBD3904EC385702A2B8B666A980AE3C982"; FileName = $pwdir + "\Repl_Metadata_Collector.sql"; FileSize = 23414}
38-
,[PSCustomObject]@{Algorithm = "SHA512"; Hash = "3089C42E8B2A1F4DE4EDD172C4D43F978147DB875D25989662C36286C755F46C462CF8AB1A163083B8BBB4973F97AC333752D5CFBDE2BBEFDDA1556CBC884485"; FileName = $pwdir + "\SQL_Server_PerfStats_Snapshot.sql"; FileSize = 36982}
39-
,[PSCustomObject]@{Algorithm = "SHA512"; Hash = "275BF48FF8C495B6BA9217D2E5A3F7A7D1A7BDFF32AF035A2E9A03AF18773522816C6484B6F463C123B78572EF586CE846D9C1C36917E398A20E094D3836C58C"; FileName = $pwdir + "\SQL_Server_PerfStats.sql"; FileSize = 73276}
40-
,[PSCustomObject]@{Algorithm = "SHA512"; Hash = "98DD9089860E83AD5116AFC88E8A58EF18F3BC99FE68AC4E37765AF3442D58D2DC3C6826E860C0F0604B2C4733F33396F0894C2ACA9E905346D7C4D5A4854185"; FileName = $parentdir + "\SQL_LogScout.cmd"; FileSize = 2564}
41-
,[PSCustomObject]@{Algorithm = "SHA512"; Hash = "FC0FA00B999C9A6BF8CD55033A530C35D47F95CEE0156D540C77480E91180C7B9DBD303D5B73208D2C783D1FE628BF88AC845A4A452DD2FE3563E15E35A91BBD"; FileName = $pwdir + "\SQL_Server_Mem_Stats.sql"; FileSize = 35326}
42-
,[PSCustomObject]@{Algorithm = "SHA512"; Hash = "96CD13704AD380D61BC763479C1509F5B6EFCC678558AE8EACE1869C4BCD1B80767115D109402E9FDF52C144CFD5D33AAFFF23FE6CFFDF62CD99590B37D5D6CF"; FileName = $pwdir + "\SSB_DbMail_Diag.sql"; FileSize = 12477}
43-
,[PSCustomObject]@{Algorithm = "SHA512"; Hash = "2269D31F61959F08646C3E8B595191A110A8B559DEE43A60A5267B52A04F6A895E808CF2EC7C21B212BCAF9DD5AF3C25101B3C0FB91E8C1D6A2D1E42C9567FEC"; FileName = $pwdir + "\TempDB_and_Tran_Analysis.sql"; FileSize = 19749}
44-
,[PSCustomObject]@{Algorithm = "SHA512"; Hash = "26FB26FBC977B8DD1D853CBE3ABD9FFAA87743CF7048F5E6549858422749B9BD8D6F2CA1AFE35C3A703407E252D8F3CDC887460D2400E69063E99E9E76D4AFFB"; FileName = $pwdir + "\xevent_AlwaysOn_Data_Movement.sql"; FileSize = 23164}
45-
,[PSCustomObject]@{Algorithm = "SHA512"; Hash = "4EE3B0EE6CEA79CA9611489C2A351A7CCB27D3D5AD2691BE6380BF9C2D6270EE0CFC639B584A2307856384E7AA3B08462BCEA288D954786576DAFC4346670376"; FileName = $pwdir + "\xevent_backup_restore.sql"; FileSize = 1178}
46-
,[PSCustomObject]@{Algorithm = "SHA512"; Hash = "DE42C1F05E42FF67BBE576EA8B8ADF443DD2D889CBE34F50F4320BE3DC793AF88F5DE13FDC46147CA69535691CC78ADB89463602F5364ED332F6F09A254B7948"; FileName = $pwdir + "\xevent_core.sql"; FileSize = 8134}
47-
,[PSCustomObject]@{Algorithm = "SHA512"; Hash = "9E09DC85282A3870A339B4928AE1E3D4ECE34B5346DA9E52BD18712A6E3D07241D80083C4A18206BBBA4D2971F13BC937CE6062C76FD83189D66B8704B0CBA1A"; FileName = $pwdir + "\xevent_detailed.sql"; FileSize = 25312}
48-
,[PSCustomObject]@{Algorithm = "SHA512"; Hash = "2C5A3942093AC02FDE94626B327F6073056E4C14DA8AA13FE69404EFBABDF935B8622BA77316F630A2B313B7CE1EF20BC5A0A37E69FE38FFFCD794C16D82A71C"; FileName = $pwdir + "\xevent_general.sql"; FileSize = 20705}
49-
,[PSCustomObject]@{Algorithm = "SHA512"; Hash = "F643167BBC7C3BAAA3A9916A5A83C951DEC49A11DF7335E231D778F02C5271C934A3EDBEE8DC01B7F0624B54C8AB37576289441C8A1867F02620F4B6328CCBAC"; FileName = $pwdir + "\xevent_servicebroker_dbmail.sql"; FileSize = 39706}
50-
,[PSCustomObject]@{Algorithm = "SHA512"; Hash = "BF31CC80FDA7ED1DD52C88AE797B1FA186770DF005F3428D09785AD2307D6C059B71E5D8AF4EBF6A6AE60FF730519F25CEA934604BDD37CE8060BB38788CB497"; FileName = $pwdir + "\NeverEndingQuery_perfstats.sql"; FileSize = 6866}
27+
[PSCustomObject]@{Algorithm = "SHA512"; Hash = "F81C8F5372C6362539BFB554EA1FF857029BB205BF161E8F0D69843B296F333566F0F0C0D6ECD9D055902275CD60EB83C10ACA9083A48CEE47F6575A32E355AF"; FileName = $parentdir + "\SQL_LogScout.cmd"; FileSize = 2253}
5128
)
5229
# global array to keep a System.IO.FileStream object for each of the non-Powershell files
5330
# files are opened with Read sharing before being hashed
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
<#
2+
.SYNOPSIS
3+
This module export SQL Script out of PSM files.
4+
5+
.DESCRIPTION
6+
In order to make it easy for developers to work directly with SQL files, this script will extract the SQL content of SQLScript_ file(s) and save it as pure .SQL file
7+
Later the same file can be converted again to PSM1 file using ConvertSQL2PSM.ps1.
8+
9+
.PARAMETER CollectorName
10+
This parameter has a list of all current Collector/Script names (AlwaysOn_Data_Movement..etc), this will help you choose a specific collector to export,
11+
You can alternatively chose to convert "ALL" scripts at once.
12+
13+
.INPUTS
14+
None. You can't pipe objects to Add-Extension.
15+
16+
.OUTPUTS
17+
SQL File(s) for choosen collector or ALL collectors exported in the same folder BIN\DevUtils.
18+
19+
.EXAMPLE
20+
PS> ConvertPSM2SQL.ps1 -CollectorName Change_Tracking
21+
.EXAMPLE
22+
PS> ConvertPSM2SQL.ps1 -CollectorName ALL
23+
.LINK
24+
Online documenation: https://mssql-support.visualstudio.com/SQL%20LogScout/_wiki/wikis/SQL-LogScout.wiki/110/Working-TSQL-Scripts
25+
26+
#>
27+
28+
Param(
29+
[Parameter(Mandatory=$true)]
30+
[ValidateSet ("ALL", #this shall trigger conversion of all scripts by enumerating the files SQLScript_* files in bin folder
31+
"AlwaysOnDiagScript",
32+
"Change_Tracking",
33+
"ChangeDataCapture",
34+
"FullTextSearchMetadata",
35+
"High_IO_Perfstats",
36+
"HighCPU_perfstats",
37+
"linked_server_config",
38+
"MiscDiagInfo",
39+
"MSDiagProcs",
40+
"NeverEndingQuery_perfstats",
41+
"ProfilerTraces",
42+
"QueryStore",
43+
"Repl_Metadata_Collector",
44+
"SQL_Server_Mem_Stats",
45+
"SQL_Server_PerfStats_Snapshot",
46+
"SQL_Server_PerfStats",
47+
"SSB_DbMail_Diag",
48+
"TempDB_and_Tran_Analysis",
49+
"xevent_AlwaysOn_Data_Movement",
50+
"xevent_backup_restore",
51+
"xevent_core",
52+
"xevent_detailed",
53+
"xevent_general",
54+
"xevent_servicebroker_dbmail")]
55+
[String]$CollectorName
56+
)
57+
58+
59+
#This function will convert a psm file to a TSQL file to helep developers change TSQL code and later convert it again to psm1 file using the the utilit ConvertSQL2PSM.ps1
60+
61+
function convertFile2SQL([String] $cName)
62+
{
63+
#since we are working inside bin\DevUtils we need to get the parent folder path to read the SQLScript*.psm1 files.
64+
$parentPath = Split-Path -Path $PSScriptRoot -Parent
65+
$fileFullName = $parentPath + "\" + "SQLScript_" + $cName + ".psm1"
66+
$SQLFileName = $cName + ".sql"
67+
68+
$functionName = $cName + "_Query"
69+
70+
if (-Not (Test-Path ($fileFullName)))
71+
{
72+
Write-Host "$fileFullname Does not exist, exiting "
73+
Exit
74+
}
75+
76+
77+
#import the psm1 file
78+
Import-Module $fileFullName
79+
80+
#return the content the tsql content as a variable
81+
$content = & $functionName -returnVariable $true
82+
83+
#Remove trailing empty spaces.
84+
while ([string]::IsNullOrEmpty( $content[-1].Trim())) {
85+
$content = $content[0..($content.Length - 2)]
86+
}
87+
88+
89+
#write the content to tsql file name inside DevUtils
90+
Set-Content -Path $SQLFileName -Value $content
91+
92+
Write-Host "$SQLFileName saved to disk"
93+
94+
95+
}
96+
97+
Import-Module "..\CommonFunctions.psm1"
98+
Import-Module "..\LoggingFacility.psm1"
99+
100+
#if user choses a specific collector, then we test if the file exists then call the function to convert.
101+
if (($CollectorName -ne "ALL") )
102+
{
103+
convertFile2SQL -cName $CollectorName
104+
105+
}
106+
elseif ($CollectorName -eq "ALL")
107+
{
108+
$parentPath = Split-Path -Path $PSScriptRoot -Parent
109+
#Write-Host $parentPath
110+
$files = Get-ChildItem -Path $parentPath -Filter SQLScript*.psm1
111+
112+
foreach ($file in $files)
113+
{
114+
#Remove extension from file name
115+
$fName = [System.IO.Path]::GetFileNameWithoutExtension($file.Name)
116+
117+
#Remove SQLSCript_ to extract collector's name
118+
$fName = $fName -replace "SQLScript_", ""
119+
120+
convertFile2SQL -cName $fName
121+
122+
}
123+
124+
}
Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
<#
2+
.SYNOPSIS
3+
This module .SQL files to PSM1 modules.
4+
5+
.DESCRIPTION
6+
This file will convert all files with extension .SQL in BIN\DevUtils to SQLScript_<CollectorName>.psm1 files in BIN folder.
7+
All converted SQL files will be moved to _sql.txt files to avoid double conversion.
8+
9+
.INPUTS
10+
None. You can't pipe objects to Add-Extension.
11+
12+
.OUTPUTS
13+
All files of .sql extension converted to SQLScript_<collectorName>.psm1
14+
15+
.EXAMPLE
16+
PS> ConvertSQL2PSM.ps1
17+
18+
19+
.LINK
20+
Online documenation: https://mssql-support.visualstudio.com/SQL%20LogScout/_wiki/wikis/SQL-LogScout.wiki/110/Working-TSQL-Scripts
21+
22+
#>
23+
24+
<#
25+
This function will take TSQL filename as input (tsql.sql) and convert it to a pouwershell module (psm1) file.
26+
The fill will containe a single function that will generate the tsql file.
27+
28+
The function name will be <fileName_without_extension>_Query
29+
30+
31+
#>
32+
33+
function convertFile2PSM ([String] $fileName)
34+
{
35+
#clean the file from its extension, this will provide us with collector name
36+
$fileName = [System.IO.Path]::GetFileNameWithoutExtension($fileName)
37+
38+
#since we run this script in bin\devutils we get he parent path to write output files to.
39+
$path = Split-Path $PSScriptRoot -Parent
40+
41+
#adding .sql file extension to collector name
42+
$filepath = $fileName + ".sql"
43+
44+
#output file name will be SQLScript_<collector name>.psm1
45+
$outputName = $path + "\SQLScript_" + $fileName + ".psm1"
46+
47+
#function name will be <collector name>_Query
48+
$functionName = $fileName + "_Query([Boolean] `$returnVariable = `$false)"
49+
50+
# Read the content of the text file
51+
$content = Get-Content -Path $filePath -Raw
52+
53+
# Escape special characters and double quotes
54+
$escapedContent = $content -replace '"', '`"' -replace '\$', '`$'
55+
56+
57+
$fileHeader = "
58+
function $functionName
59+
{
60+
Write-LogDebug `"Inside`" `$MyInvocation.MyCommand
61+
62+
[String] `$collectorName = `"" + $fileName +"`"
63+
[String] `$fileName = `$global:internal_output_folder + `$collectorName + `".sql`"
64+
65+
`$content = `"
66+
$escapedContent
67+
`"
68+
69+
if (`$true -eq `$returnVariable)
70+
{
71+
Write-LogDebug `"Returned variable without creating file, this maybe due to use of GUI to filter out some of the xevents`"
72+
73+
`$content = `$content -split `"``r``n`"
74+
return `$content
75+
}
76+
77+
if (-Not (Test-Path `$fileName))
78+
{
79+
Set-Content -Path `$fileName -Value `$content
80+
} else
81+
{
82+
Write-LogDebug `"`$filName already exists, could be from GUI`"
83+
}
84+
85+
#check if command was successful, then add the file to the list for cleanup AND return collector name
86+
if (`$true -eq `$?)
87+
{
88+
`$global:tblInternalSQLFiles += `$collectorName
89+
return `$collectorName
90+
}
91+
92+
Write-LogDebug `"Failed to build SQL File `"
93+
Write-LogDebug `$fileName
94+
95+
#return false if we reach here.
96+
return `$false
97+
98+
}
99+
"
100+
#if output file exists, we can compare content before we write it again to disk
101+
[Boolean] $fileExist = Test-Path $outputName
102+
if ($true -eq $fileExist)
103+
{
104+
$origContent = Get-Content $outputName
105+
#remove trailing spaces.
106+
while ([string]::IsNullOrEmpty( $origContent[-1].Trim())) {
107+
$origContent = $origContent[0..($origContent.Length - 2)]
108+
}
109+
}
110+
111+
112+
#if the existing file is the same as new file, do not write it to disk
113+
if (($true -eq $fileExist) -and ($origContent.Equals($fileHeader)))
114+
{
115+
Write-Host "$fileName has the same content, no writing is done"
116+
}
117+
else {
118+
# Output the escaped content
119+
Set-Content -Path $outputName -Value $fileHeader
120+
write-host "Converted $outputName"
121+
$newFileName = $fileName + "_sql.txt"
122+
Move-Item -Path $filepath -Destination $newFileName -Force
123+
}
124+
125+
} #end of convertFile2PSM
126+
127+
#Main body of the script, get a colleection of all .sql files present in BIN\DevUtils folder.
128+
$files = Get-ChildItem -Path . -Filter *.sql | Where-Object { $_.Name -notMatch "del_*" }
129+
130+
131+
if ($null -eq $files) {
132+
Write-Host "No files to process"
133+
exit
134+
}
135+
#Process each .sql file to creat .psm1 file
136+
foreach ($file in $files)
137+
{
138+
Write-Host $file.Name
139+
convertFile2PSM -fileName $file.Name
140+
141+
}
142+
143+

0 commit comments

Comments
 (0)