Lokasi ngalangkungan proxy:   [ UP ]  
[Ngawartoskeun bug]   [Panyetelan cookie]                
Skip to content

Commit f0329cb

Browse files
authored
Update sql-server-linux-sql-assessment-api.md
1 parent 8041810 commit f0329cb

1 file changed

Lines changed: 21 additions & 22 deletions

File tree

docs/linux/sql-server-linux-sql-assessment-api.md

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ description: This article describes how to run the SQL Assessment API for SQL Se
44
author: aravindmahadevan-ms
55
ms.author: armaha
66
ms.reviewer: amitkh-msft, randolphwest
7-
ms.date: 01/17/2023
7+
ms.date: 08/31/2023
88
ms.service: sql
99
ms.subservice: linux
1010
ms.topic: conceptual
@@ -110,17 +110,17 @@ if (-not ( Test-Path $outDir )) { mkdir $outDir }
110110
$outPath = Join-Path $outDir 'assessment-latest'
111111
112112
$errorPath = Join-Path $outDir 'assessment-latest-errors'
113-
if( Test-Path $errorPath ) { remove-item $errorPath }
113+
if ( Test-Path $errorPath ) { remove-item $errorPath }
114114
115115
function ConvertTo-LogOutput {
116116
[CmdletBinding()]
117117
param (
118-
[Parameter(ValueFromPipeline=$true)]
118+
[Parameter(ValueFromPipeline = $true)]
119119
$input
120120
)
121121
process {
122-
switch($input){
123-
{ $_ -is [System.Management.Automation.WarningRecord] }{
122+
switch ($input) {
123+
{ $_ -is [System.Management.Automation.WarningRecord] } {
124124
$result = @{
125125
'TimeStamp' = $(Get-Date).ToString("O");
126126
'Warning' = $_.Message
@@ -157,31 +157,31 @@ function Get-TargetsRecursive {
157157
158158
[CmdletBinding()]
159159
Param (
160-
[Parameter(ValueFromPipeline=$true)]
160+
[Parameter(ValueFromPipeline = $true)]
161161
[Microsoft.SqlServer.Management.Smo.Server] $server
162162
)
163163
164164
$server
165165
$server.Databases
166166
}
167167
168-
function Get-ConfSetting{
168+
function Get-ConfSetting {
169169
[CmdletBinding()]
170170
param (
171171
$confFile,
172172
$section,
173173
$name,
174-
$defaultValue=$null
174+
$defaultValue = $null
175175
)
176176
177177
$inSection = $false
178178
179-
switch -regex -file $confFile{
180-
"^\s*\[\s*(.+?)\s*\]"{
179+
switch -regex -file $confFile {
180+
"^\s*\[\s*(.+?)\s*\]" {
181181
$inSection = $matches[1] -eq $section
182182
}
183-
"^\s*$($name)\s*=\s*(.+?)\s*$"{
184-
if($inSection){
183+
"^\s*$($name)\s*=\s*(.+?)\s*$" {
184+
if ($inSection) {
185185
return $matches[1]
186186
}
187187
}
@@ -191,31 +191,31 @@ function Get-ConfSetting{
191191
}
192192
193193
try {
194-
195194
Write-Verbose "Acquiring credentials"
196195
197-
$login, $pwd = Get-Content '/var/opt/mssql/secrets/assessment' -Encoding UTF8NoBOM -TotalCount 2
196+
$login, $pwd = Get-Content '/var/opt/mssql/secrets/assessment' -Encoding UTF8NoBOM -TotalCount 2
198197
$securePassword = ConvertTo-SecureString $pwd -AsPlainText -Force
199-
$credential = New-Object System.Management.Automation.PSCredential ($login, $securePassword)
198+
$credential = New-Object System.Management.Automation.PSCredential ($login, $securePassword)
200199
$securePassword.MakeReadOnly()
201200
202201
Write-Verbose "Acquired credentials"
203202
204203
$serverInstance = '.'
205204
206-
if(Test-Path /var/opt/mssql/mssql.conf) {
205+
if (Test-Path /var/opt/mssql/mssql.conf) {
207206
$port = Get-ConfSetting /var/opt/mssql/mssql.conf network tcpport
208207
209208
210-
if(-not [string]::IsNullOrWhiteSpace($port)) {
209+
if (-not [string]::IsNullOrWhiteSpace($port)) {
211210
Write-Verbose "Using port $($port)"
212211
$serverInstance = "$($serverInstance),$($port)"
213212
}
214213
}
215214
216-
# IMPORTANT: If the script is run in trusted environments and there is a prelogin handshake error, add -TrustServerCertificate flag in the commands for $serverName, $hostName and Get-SqlInstance lines below.
215+
# IMPORTANT: If the script is run in trusted environments and there is a prelogin handshake error,
216+
# add -TrustServerCertificate flag in the commands for $serverName, $hostName and Get-SqlInstance lines below.
217217
$serverName = (Invoke-SqlCmd -ServerInstance $serverInstance -Credential $credential -Query "SELECT @@SERVERNAME")[0]
218-
$hostName = (Invoke-SqlCmd -ServerInstance $serverInstance -Credential $credential -Query "SELECT HOST_NAME()")[0]
218+
$hostName = (Invoke-SqlCmd -ServerInstance $serverInstance -Credential $credential -Query "SELECT HOST_NAME()")[0]
219219
220220
# Invoke assessment and store results.
221221
# Replace 'ConvertTo-Json' with 'ConvertTo-Csv' to change output format.
@@ -224,14 +224,13 @@ try {
224224
225225
Get-SqlInstance -ServerInstance $serverInstance -Credential $credential -ErrorAction Stop
226226
| Get-TargetsRecursive
227-
| %{ Write-Verbose "Invoke assessment on $($_.Urn)"; $_ }
227+
| ForEach-Object { Write-Verbose "Invoke assessment on $($_.Urn)"; $_ }
228228
| Invoke-SqlAssessment 3>&1
229229
| ConvertTo-LogOutput
230230
| ConvertTo-Json -AsArray
231231
| Set-Content $outPath -Encoding UTF8NoBOM
232232
}
233233
finally {
234-
235234
Write-Verbose "Error count: $($Error.Count)"
236235
237236
if ($Error) {
@@ -243,7 +242,7 @@ finally {
243242
}
244243
```
245244
> [!NOTE]
246-
> In the above script, when it is run in trusted environments and there is a prelogin handshake error, add -TrustServerCertificate flag in the commands for $serverName, $hostName and Get-SqlInstance lines in the above code. .
245+
> When you run the previous script in trusted environments, and you get a prelogin handshake error, add the `-TrustServerCertificate` flag in the commands for `$serverName`, `$hostName` and `Get-SqlInstance` lines in the code.
247246
248247
### Run the assessment
249248

0 commit comments

Comments
 (0)