Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 165c3b9

Browse files
Merge branch 'development' into diffcontinue
2 parents 8b79a0b + 5e86342 commit 165c3b9

15 files changed

+774
-511
lines changed

‎allcommands.ps1‎

Lines changed: 303 additions & 184 deletions
Large diffs are not rendered by default.

‎bin/dbatools-index.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3535,7 +3535,7 @@
35353535
"Synopsis": "Remove-DbaAgentJob removes a job.",
35363536
"Name": "Remove-DbaAgentJob",
35373537
"Links": "https://dbatools.io/Remove-DbaAgentJob",
3538-
"Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eRemove-DbaAgentJob -SqlInstance sql1 -Job Job1\r\n\r\nRemoves the job from the instance with the name Job1\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eRemove-DbaAgentJob -SqlInstance sql1 -Job Job1 -KeepHistory\r\n\r\nRemoves the job but keeps the history\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 3 --------------------------\r\n\r\nPS C:\\\u003eRemove-DbaAgentJob -SqlInstance sql1 -Job Job1 -KeepUnusedSchedule\r\n\r\nRemoves the job but keeps the unused schedules\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 4 --------------------------\r\n\r\nPS C:\\\u003eRemove-DbaAgentJob -SqlInstance sql1, sql2, sql3 -Job Job1\r\n\r\nRemoves the job from multiple servers\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 5 --------------------------\r\n\r\nPS C:\\\u003esql1, sql2, sql3 | Remove-DbaAgentJob -Job Job1\r\n\r\nRemoves the job from multiple servers using pipe line\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n"
3538+
"Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eRemove-DbaAgentJob -SqlInstance sql1 -Job Job1\r\n\r\nRemoves the job from the instance with the name Job1\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eGetDbaAgentJob -SqlInstance sql1 -Job Job1 | Remove-DbaAgentJob -KeepHistory\r\n\r\n\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 3 --------------------------\r\n\r\nPS C:\\\u003eRemove-DbaAgentJob -SqlInstance sql1 -Job Job1 -KeepUnusedSchedule\r\n\r\nRemoves the job but keeps the unused schedules\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 4 --------------------------\r\n\r\nPS C:\\\u003eRemove-DbaAgentJob -SqlInstance sql1, sql2, sql3 -Job Job1\r\n\r\nRemoves the job from multiple servers\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n"
35393539
},
35403540
{
35413541
"CommandName": "Remove-DbaAgentJobCategory",

‎bin/diagnosticquery/SQLServerDiagnosticQueries_2014_201806.sql‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
-- SQL Server 2014 Diagnostic Information Queries
33
-- Glenn Berry
4-
-- Last Modified: July 10, 2018
4+
-- Last Modified: August 1, 2018
55
-- https://www.sqlskills.com/blogs/glenn/
66
-- http://sqlserverperformance.wordpress.com/
77
-- Twitter: GlennAlanBerry
@@ -1346,6 +1346,7 @@ qs.max_elapsed_time, qs.last_elapsed_time, qs.total_elapsed_time, qs.execution_c
13461346
ISNULL(qs.execution_count/DATEDIFF(Minute, qs.cached_time, GETDATE()), 0) AS [Calls/Minute],
13471347
qs.total_worker_time/qs.execution_count AS [AvgWorkerTime],
13481348
qs.total_worker_time AS [TotalWorkerTime],
1349+
CASE WHEN CONVERT(nvarchar(max), qp.query_plan) LIKE N'%<MissingIndexes>%' THEN 1 ELSE 0 END AS [Has Missing Index],
13491350
FORMAT(qs.last_execution_time, 'yyyy-MM-dd HH:mm:ss', 'en-US') AS [Last Execution Time],
13501351
FORMAT(qs.cached_time, 'yyyy-MM-dd HH:mm:ss', 'en-US') AS [Plan Cached Time]
13511352
-- ,qp.query_plan AS [Query Plan] -- Uncomment if you want the Query Plan

‎bin/diagnosticquery/SQLServerDiagnosticQueries_AzureSQLDatabase_201806.sql‎

Lines changed: 132 additions & 117 deletions
Large diffs are not rendered by default.

‎dbatools.psd1‎

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
RootModule = 'dbatools.psm1'
1212

1313
# Version number of this module.
14-
ModuleVersion = '0.9.382'
14+
ModuleVersion = '0.9.383'
1515

1616
# ID used to uniquely identify this module
1717
GUID = '9d139310-ce45-41ce-8e8b-d76335aa1789'
@@ -636,8 +636,8 @@
636636
# SIG # Begin signature block
637637
# MIIcYgYJKoZIhvcNAQcCoIIcUzCCHE8CAQExCzAJBgUrDgMCGgUAMGkGCisGAQQB
638638
# gjcCAQSgWzBZMDQGCisGAQQBgjcCAR4wJgIDAQAABBAfzDtgWUsITrck0sYpfvNR
639-
# AgEAAgEAAgEAAgEAAgEAMCEwCQYFKw4DAhoFAAQUcg1+stRKtsciDClrcTJVWbkN
640-
# XcaggheRMIIFGjCCBAKgAwIBAgIQAsF1KHTVwoQxhSrYoGRpyjANBgkqhkiG9w0B
639+
# AgEAAgEAAgEAAgEAAgEAMCEwCQYFKw4DAhoFAAQUNPW41nxMRx916hn8imJijlT+
640+
# dgCggheRMIIFGjCCBAKgAwIBAgIQAsF1KHTVwoQxhSrYoGRpyjANBgkqhkiG9w0B
641641
# AQsFADByMQswCQYDVQQGEwJVUzEVMBMGA1UEChMMRGlnaUNlcnQgSW5jMRkwFwYD
642642
# VQQLExB3d3cuZGlnaWNlcnQuY29tMTEwLwYDVQQDEyhEaWdpQ2VydCBTSEEyIEFz
643643
# c3VyZWQgSUQgQ29kZSBTaWduaW5nIENBMB4XDTE3MDUwOTAwMDAwMFoXDTIwMDUx
@@ -768,22 +768,22 @@
768768
# c3N1cmVkIElEIENvZGUgU2lnbmluZyBDQQIQAsF1KHTVwoQxhSrYoGRpyjAJBgUr
769769
# DgMCGgUAoHgwGAYKKwYBBAGCNwIBDDEKMAigAoAAoQKAADAZBgkqhkiG9w0BCQMx
770770
# DAYKKwYBBAGCNwIBBDAcBgorBgEEAYI3AgELMQ4wDAYKKwYBBAGCNwIBFTAjBgkq
771-
# hkiG9w0BCQQxFgQUdG2Fo/PbzWFmZedjcjmLyrP44YgwDQYJKoZIhvcNAQEBBQAE
772-
# ggEAElSxl4Qv/E8dohZIJGeuTlQ6UO34suOwpEo75azyiehKk1aze0czm9WDSO44
773-
# PO04O4boDXmFtRMKWQq1j48bN2bouML7qSE1hzcPwfXcdTVjrSbkVsX1M18gbRB0
774-
# c/I2GzsiNtbk99ru+xWSgnR3kotl0mAzYxY7RE6fXOx2CPQtiyCpe9ChKnxcRMCd
775-
# 63l+X6PypS3Rs/VtbKXOo02gbgyzyeOidJDgn+YMh6w/tme5FY/1USzOxboM3xNB
776-
# GJ6mg+WvuABQbcPNvGWQd9xFSyfW4MxWdjxKAGjejQJVme8ZL/FsqWAy1B4/4Yl8
777-
# FpvQc8TP7jZsq8375ImW9apyjaGCAg8wggILBgkqhkiG9w0BCQYxggH8MIIB+AIB
771+
# hkiG9w0BCQQxFgQUJHfZV+0Hean4PVLhUa5c2Z7vqYswDQYJKoZIhvcNAQEBBQAE
772+
# ggEAcEwRTPnbtYCIsL5Nhq3oidaj8UcpN/ZhWJkLnWLxPWGqLml/UO0lfIU0Vm9a
773+
# d6ox1rwXBMSfblJ54mnIXyVYs8C6H/L41omRhW7oTGc/1hY5f3knQqoBXiK/4stE
774+
# 4AsD5TWdUTc3mLdCXgtl0Y3clJRdN4sn8/neEDWDaiZ6KaeBz9NowqLc5pHcZWRB
775+
# HnBS72AguR7sW3famk3lID3T+X+fzKX1xZr79qArb9HOWuecKj7d+STHT8VX6emk
776+
# MqQt28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vpYOgbD
784+
# 4s+JoeBtkd5/2eLwX5HtCvCFRx2LhITFOcgRdbJxVU6PXAPH8HuOHSXO+80pj0H/
785+
# yWLWrH2JwruSByE63zR24FAPwqnj18YfnXjiz10tI+JjxGMWtnKvEna42MlN2T3o
786+
# OtiJOSTr7jKXy730FhYtn08PZV7+gzMofk5tkkvLUbqBfzB5BUaF+boJ0Q4XBZg6
787+
# t6W2+YkwIKrs4rhq4ReQJzKZ1mTqLXOzGtYYv5tGDjfDcKzgTEDyk6NXkbvK76kH
788+
# CG8qPrvxHSNmufoUq0HSMZhyTyZzHA==
789789
# SIG # End signature block

‎dbatools.psm1‎

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -680,8 +680,8 @@ if ($PSCommandPath -like "*.psm1") {
680680
# SIG # Begin signature block
681681
# MIIcYgYJKoZIhvcNAQcCoIIcUzCCHE8CAQExCzAJBgUrDgMCGgUAMGkGCisGAQQB
682682
# gjcCAQSgWzBZMDQGCisGAQQBgjcCAR4wJgIDAQAABBAfzDtgWUsITrck0sYpfvNR
683-
# AgEAAgEAAgEAAgEAAgEAMCEwCQYFKw4DAhoFAAQUlvm9Bw+nnAYfIrfFLl3c131k
684-
# pjOggheRMIIFGjCCBAKgAwIBAgIQAsF1KHTVwoQxhSrYoGRpyjANBgkqhkiG9w0B
683+
# AgEAAgEAAgEAAgEAAgEAMCEwCQYFKw4DAhoFAAQUzuBEXrAUO3NVvftZe0Zh4NV5
684+
# 4eeggheRMIIFGjCCBAKgAwIBAgIQAsF1KHTVwoQxhSrYoGRpyjANBgkqhkiG9w0B
685685
# AQsFADByMQswCQYDVQQGEwJVUzEVMBMGA1UEChMMRGlnaUNlcnQgSW5jMRkwFwYD
686686
# VQQLExB3d3cuZGlnaWNlcnQuY29tMTEwLwYDVQQDEyhEaWdpQ2VydCBTSEEyIEFz
687687
# c3VyZWQgSUQgQ29kZSBTaWduaW5nIENBMB4XDTE3MDUwOTAwMDAwMFoXDTIwMDUx
@@ -812,22 +812,22 @@ if ($PSCommandPath -like "*.psm1") {
812812
# c3N1cmVkIElEIENvZGUgU2lnbmluZyBDQQIQAsF1KHTVwoQxhSrYoGRpyjAJBgUr
813813
# DgMCGgUAoHgwGAYKKwYBBAGCNwIBDDEKMAigAoAAoQKAADAZBgkqhkiG9w0BCQMx
814814
# DAYKKwYBBAGCNwIBBDAcBgorBgEEAYI3AgELMQ4wDAYKKwYBBAGCNwIBFTAjBgkq
815-
# hkiG9w0BCQQxFgQUkaq1VfzE0aX1eAZGl6ccIX4i784wDQYJKoZIhvcNAQEBBQAE
816-
# ggEAI5NEv67pv0Bs0d46wCVhShxYCialeB0IMSL8uCQrY3YCJT83oOGIAtcnHHSA
817-
# XA7a5mgpLIDqymtTthepID26k9jhSJu/tCGw732DTg/ucEIKf5UTG8T1ocHl80JB
818-
# hYhXlw7k87DdZmDa6W2FxeXtXWDgbLfs2FOhze0VarVLZlC1xrfMVqF3okq2eTPq
819-
# YwoLHZq3Oaoap6xYTtauA4tIDvCnnr2l3mYNpOov3s1NXUWUJtACvqJjgdocVaCn
820-
# TktFhHMRkjT0P0hZNNEtlUHRiOYG15pWdWEHTOIW3TnWU5KTuytmafzbRmTLgxS2
821-
# AWyggWtVPJV5XrOKFUPKFyczVaGCAg8wggILBgkqhkiG9w0BCQYxggH8MIIB+AIB
815+
# hkiG9w0BCQQxFgQUJc2L50QWUHDa0np5rcTx8UP3gDYwDQYJKoZIhvcNAQEBBQAE
816+
# ggEAX7wLIuvfa8sUpLjhZGLS7eWmJL01TOuSF2aSx2m9ARpzLTFEvitaSoKVZ0+E
817+
# mkAZZgGXbpPm79U5AXC/yhwD420gpYL6GFgIqZSADoDyToCzYJOvtteMlI1IqKPz
818+
# JB5G+IxFgNBtTtobtS4cquRb/gKwoLY4AVM/MxTfKvxfcDBxrYmNj1UQuRyrYvpv
819+
# FhMYEk3S9ou0uI9NXmr2JyfRx8sD1ewB8GWDMjknWTB8EpLfFOK0FlU3vQ4gEwSJ
820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MCd80CH3azt
828+
# gphDoXH3GhPNAVITlpiUnJeNswQWjk33W1zq6Loe5H/SwvJJ5Bverv0C5I1Y5mS3
829+
# sFLN8yqBWSXn2P8aOex8qi+uZYwYLG6+CeWG64v4sZFO1yPqiMl5ovU/EPghIw86
830+
# 0LutBRVI6ZA3uCTZKqrWx2SXZW8pfZv19Hb9laf0yOE5/R3uVG/UAUxv5Ztq9mW6
831+
# uTU9pXhv1Xi2b/NXtAgvIjJmXv+BBEtmknhhKPm0d333trVka0ByKKcmUWFRE05U
832+
# 8LxPATeFx37SvlQrFUMk37haJrEc9A==
833833
# SIG # End signature block

‎functions/Backup-DbaDbCertificate.ps1‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ function Backup-DbaDbCertificate {
142142
$actualPath = Get-SqlDefaultPaths -SqlInstance $server -filetype Data
143143
}
144144

145+
$actualPath = $actualPath.TrimEnd('\')
145146
$fullCertName = "$actualPath\$certName$Suffix"
146147
$exportPathKey = "$fullCertName.pvk"
147148

‎functions/Install-DbaFirstResponderKit.ps1‎

Lines changed: 78 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,13 @@ function Install-DbaFirstResponderKit {
2424
.PARAMETER Branch
2525
Specifies an alternate branch of the First Responder Kit to install. (master or dev)
2626
27+
.PARAMETER LocalFile
28+
Specifies the path to a local file to install FRK from. This *should* be the zipfile as distributed by the maintainers.
29+
If this parameter is not specified, the latest version will be downloaded and installed from https://github.com/BrentOzarULTD/SQL-Server-First-Responder-Kit
30+
31+
.PARAMETER Force
32+
If this switch is enabled, the FRK will be downloaded from the internet even if previously cached.
33+
2734
.PARAMETER Confirm
2835
Prompts to confirm actions
2936
@@ -85,57 +92,90 @@ function Install-DbaFirstResponderKit {
8592
[ValidateSet('master', 'dev')]
8693
[string]$Branch = "master",
8794
[object]$Database = "master",
95+
[string]$LocalFile,
96+
[switch]$Force,
8897
[Alias('Silent')]
8998
[switch]$EnableException
9099
)
91100

92101
begin {
93-
$url = "https://codeload.github.com/BrentOzarULTD/SQL-Server-First-Responder-Kit/zip/$Branch"
102+
$DbatoolsData = Get-DbaConfigValue -FullName "Path.DbatoolsData"
103+
104+
$url = "https://github.com/BrentOzarULTD/SQL-Server-First-Responder-Kit/archive/$Branch.zip"
94105

95106
$temp = ([System.IO.Path]::GetTempPath()).TrimEnd("\")
96107
$zipfile = "$temp\SQL-Server-First-Responder-Kit-$Branch.zip"
97108
$zipfolder = "$temp\SQL-Server-First-Responder-Kit-$Branch\"
98-
99-
if ($zipfile | Test-Path) {
100-
Remove-Item -Path $zipfile -ErrorAction SilentlyContinue
101-
}
102-
103-
if ($zipfolder | Test-Path) {
104-
Remove-Item -Path $zipfolder -Recurse -ErrorAction SilentlyContinue
109+
$FRKLocation = "FRK_$Branch"
110+
$LocalCachedCopy = Join-Path -Path $DbatoolsData -ChildPath $FRKLocation
111+
if ($LocalFile) {
112+
if (-not(Test-Path $LocalFile)) {
113+
Stop-Function -Message "$LocalFile doesn't exist"
114+
return
115+
}
116+
if (-not($LocalFile.EndsWith('.zip'))) {
117+
Stop-Function -Message "$LocalFile should be a zip file"
118+
return
119+
}
105120
}
106121

107-
$null = New-Item -ItemType Directory -Path $zipfolder -ErrorAction SilentlyContinue
108-
109-
Write-Message -Level Verbose -Message "Downloading and unzipping the First Responder Kit zip file."
110-
111-
try {
112-
$oldSslSettings = [System.Net.ServicePointManager]::SecurityProtocol
113-
[System.Net.ServicePointManager]::SecurityProtocol = "Tls12"
114-
try {
115-
$wc = New-Object System.Net.WebClient
116-
$wc.DownloadFile($url, $zipfile)
122+
if ($Force -or -not(Test-Path -Path $LocalCachedCopy -PathType Container) -or $LocalFile) {
123+
# Force was passed, or we don't have a local copy, or $LocalFile was passed
124+
if ($zipfile | Test-Path) {
125+
Remove-Item -Path $zipfile -ErrorAction SilentlyContinue
117126
}
118-
catch {
119-
# Try with default proxy and usersettings
120-
$wc = New-Object System.Net.WebClient
121-
$wc.Proxy.Credentials = [System.Net.CredentialCache]::DefaultNetworkCredentials
122-
$wc.DownloadFile($url, $zipfile)
127+
if ($zipfolder | Test-Path) {
128+
Remove-Item -Path $zipfolder -Recurse -ErrorAction SilentlyContinue
123129
}
124-
[System.Net.ServicePointManager]::SecurityProtocol = $oldSslSettings
125130

126-
# Unblock if there's a block
127-
Unblock-File $zipfile -ErrorAction SilentlyContinue
131+
$null = New-Item -ItemType Directory -Path $zipfolder -ErrorAction SilentlyContinue
132+
if ($LocalFile) {
133+
Unblock-File $LocalFile -ErrorAction SilentlyContinue
134+
Expand-Archive -Path $LocalFile -DestinationPath $zipfolder -Force
135+
}
136+
else {
137+
Write-Message -Level Verbose -Message "Downloading and unzipping the First Responder Kit zip file."
138+
139+
try {
140+
$oldSslSettings = [System.Net.ServicePointManager]::SecurityProtocol
141+
[System.Net.ServicePointManager]::SecurityProtocol = "Tls12"
142+
try {
143+
$wc = New-Object System.Net.WebClient
144+
$wc.DownloadFile($url, $zipfile)
145+
}
146+
catch {
147+
# Try with default proxy and usersettings
148+
$wc = New-Object System.Net.WebClient
149+
$wc.Proxy.Credentials = [System.Net.CredentialCache]::DefaultNetworkCredentials
150+
$wc.DownloadFile($url, $zipfile)
151+
}
152+
[System.Net.ServicePointManager]::SecurityProtocol = $oldSslSettings
128153

129-
Expand-Archive -Path $zipfile -DestinationPath $zipfolder -Force
154+
# Unblock if there's a block
155+
Unblock-File $zipfile -ErrorAction SilentlyContinue
130156

131-
Remove-Item -Path $zipfile
132-
}
133-
catch {
134-
Stop-Function -Message "Couldn't download the First Responder Kit. Download and install manually from https://github.com/BrentOzarULTD/SQL-Server-First-Responder-Kit/archive/$Branch.zip." -ErrorRecord $_
135-
return
157+
Expand-Archive -Path $zipfile -DestinationPath $zipfolder -Force
158+
159+
Remove-Item -Path $zipfile
160+
}
161+
catch {
162+
Stop-Function -Message "Couldn't download the First Responder Kit. Download and install manually from https://github.com/BrentOzarULTD/SQL-Server-First-Responder-Kit/archive/$Branch.zip." -ErrorRecord $_
163+
return
164+
}
165+
}
166+
167+
## Copy it into local area
168+
if (Test-Path -Path $LocalCachedCopy -PathType Container) {
169+
Remove-Item -Path (Join-Path $LocalCachedCopy '*') -Recurse -ErrorAction SilentlyContinue
170+
}
171+
else {
172+
$null = New-Item -Path $LocalCachedCopy -ItemType Container
173+
}
174+
Copy-Item -Path $zipfolder -Destination $LocalCachedCopy -Recurse
136175
}
137176
}
138177

178+
139179
process {
140180
if (Test-FunctionInterrupt) {
141181
return
@@ -154,7 +194,7 @@ function Install-DbaFirstResponderKit {
154194
$allprocedures_query = "select name from sys.procedures where is_ms_shipped = 0"
155195
$allprocedures = ($server.Query($allprocedures_query, $Database)).Name
156196
# Install/Update each FRK stored procedure
157-
foreach ($script in (Get-ChildItem $zipfolder -Recurse -Filter "sp_*.sql")) {
197+
foreach ($script in (Get-ChildItem $LocalCachedCopy -Recurse -Filter "sp_*.sql")) {
158198
$scriptname = $script.Name
159199
$scriptError = $false
160200
if ($scriptname -ne "sp_BlitzRS.sql") {
@@ -165,7 +205,8 @@ function Install-DbaFirstResponderKit {
165205
if ($Pscmdlet.ShouldProcess($instance, "installing/updating $scriptname in $database.")) {
166206
try {
167207
Invoke-DbaSqlQuery -SqlInstance $server -Database $Database -File $script.FullName -EnableException -Verbose:$false
168-
} catch {
208+
}
209+
catch {
169210
Write-Message -Level Warning -Message "Could not execute at least one portion of $scriptname in $Database on $instance." -ErrorRecord $_
170211
$scriptError = $true
171212
}
@@ -178,7 +219,8 @@ function Install-DbaFirstResponderKit {
178219
}
179220
if ($scriptError) {
180221
$baseres['Status'] = 'Error'
181-
} elseif ($script.BaseName -in $allprocedures) {
222+
}
223+
elseif ($script.BaseName -in $allprocedures) {
182224
$baseres['Status'] = 'Updated'
183225
}
184226
else {
@@ -191,4 +233,4 @@ function Install-DbaFirstResponderKit {
191233
Write-Message -Level Verbose -Message "Finished installing/updating the First Responder Kit stored procedures in $database on $instance."
192234
}
193235
}
194-
}
236+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /