Get-SqlAssessmentItem

선택한 SQL Server 개체에 사용할 수 있는 SQL 평가 모범 사례 검사를 가져옵니다.

Syntax

Get-SqlAssessmentItem
   [-Check <String[]>]
   [[-InputObject] <PSObject>]
   [-Configuration <PSObject>]
   [-MinSeverity <SeverityLevel>]
   [-FlattenOutput]
   [<CommonParameters>]

Description

Get-SqlAssessmentItem cmdlet은 각 입력 개체에 대해 사용 가능한 모든 모범 사례 검사를 찾습니다. 자세한 내용은 SQL 평가 API 개요를 참조하세요.

이 cmdlet은 다음 입력 형식을 허용합니다.

  • Microsoft.SqlServer.Management.Smo.Server
  • Microsoft.SqlServer.Management.Smo.Database
  • Microsoft.SqlServer.Management.Smo.AvailabilityGroup
  • Microsoft.SqlServer.Management.Smo.FileGroup
  • Microsoft.SqlServer.Management.Smo.RegisteredServers.RegisteredServer
  • 위 형식의 모든 개체에 대한 경로가 포함된 문자열
  • 개체 컬렉션

Get-SqlInstance 및 Get-SqlDatabase 또는 기본 PowerShell과 같은 SqlServer cmdlet을 사용하여 입력 개체를 가져올 수 있습니다.
Get-Item 및 Get-ChildItem과 같은 cmdlet 또한 cmdlet은 SQL Server PowerShell 공급자를 지원하므로 해당 경로에서 개체를 가져올 수 있습니다. 경로를 명시적으로 전달할 수 있으며, 그렇지 않으면 현재 경로가 사용됩니다.

선택한 개체에 대한 검사 가용성은 SQL Server 버전, 플랫폼 및 개체 유형에 따라 다릅니다. 또한 또는 master와 같은 tempdb 특정 데이터베이스를 대상으로 하는 검사가 있습니다. -MinSeverity 및 -Check 매개 변수를 사용하여 태그, 이름 및 심각도별로 검사를 필터링할 수도 있습니다.

Get-SqlAssessmentItem cmdlet을 사용하면 지정된 SQL Server 개체에 적용 가능한 검사 목록을 가져올 수 있습니다. 또한 이 cmdlet의 출력을 Invoke-SqlAssessment cmdlet에 대한 -Check 인수로 사용할 수 있습니다.

-Configuration 매개 변수를 사용하여 사용자 지정 구성을 적용할 수 있습니다. 사용자 지정 예제는 Github에서 사용할 수 있습니다.

Azure VM 지원의 SQL Server

SQL Assessment cmdlet을 사용하면 온-프레미스 SQL Server 뿐만 아니라 Azure VM의 SQL Server 관련된 규칙(가상 머신 구성에 대한 정보를 사용하는 규칙)을 사용하여 Azure VM에서 SQL Server instance 평가할 수 있습니다. 예를 들어 AzSqlVmSize 규칙은 Azure VM에서 SQL Server instance 호스트하는 VM의 크기가 권장되는지 확인합니다.

이러한 규칙을 사용하려면 Azure PowerShell 모듈을 사용하여 Azure에 연결하고 Az.ResourceGraph 모듈이 설치되어 있는지 확인합니다.

Azure VM instance SQL Server 대해 SQL 평가를 호출하기 전에 Azure PowerShell 사용하여 로그인합니다. 예제 13은 대화형 로그인 프로세스 및 구독 선택을 보여줍니다.

참고. PowerShell 세션 간에 유지되는 Azure 계정 연결을 사용할 수 있습니다. 즉, 한 세션에서 Connect-AzAccount 호출하고 나중에 이 명령을 생략할 수 있습니다. 그러나 현재 버전의 SQL Assessment cmdlet은 Az.ResourceGraph 모듈을 명시적으로 가져와야 합니다. Import-Module Az.ResourceGraph

예제

예제 1: 로컬 기본 instance 대한 검사 가져오기

PS:> Get-SqlInstance -ServerInstance 'localhost' | Get-SqlAssessmentItem

   Target: [LOCAL]

ID                             ON      Name                                     Origin                                  
--                             --      ----                                     ------                                  
TF1204                         True    TF 1204 returns deadlock information     Microsoft Ruleset 0.1.202               
BlackboxTrace                  True    Blackbox trace is configured and running Microsoft Ruleset 0.1.202               
HintsStatistics                True    Hints are being used                     Microsoft Ruleset 0.1.202               
PlansUseRatio                  True    Amount of single use plans in cache i... Microsoft Ruleset 0.1.202            
TempDBFilesAutoGrowth          True    Some TempDB data files have different... Microsoft Ruleset 0.1.202             
CpuUtil90                      True    CPU usage over 90%                       Microsoft Ruleset 0.1.202  
...

이 예제에서는 현재 컴퓨터에서 실행되는 SQL Server 기본 instance 사용할 수 있는 모든 검사를 가져옵니다.

예제 2: Get-Item cmdlet을 사용하여 검사 가져오기

PS:> Get-Item SQLSERVER:\SQL\localhost\default | Get-SqlAssessmentItem

   Target: [LOCAL]

ID                             ON      Name                                     Origin                                  
--                             --      ----                                     ------                                  
TF1204                         True    TF 1204 returns deadlock information     Microsoft Ruleset 0.1.202               
BlackboxTrace                  True    Blackbox trace is configured and running Microsoft Ruleset 0.1.202               
HintsStatistics                True    Hints are being used                     Microsoft Ruleset 0.1.202               
PlansUseRatio                  True    Amount of single use plans in cache i... Microsoft Ruleset 0.1.202               
TempDBFilesAutoGrowth          True    Some TempDB data files have different... Microsoft Ruleset 0.1.202               
CpuUtil90                      True    CPU usage over 90%                       Microsoft Ruleset 0.1.202  
...

이 예제에서는 현재 컴퓨터에서 실행되는 SQL Server 기본 instance 사용할 수 있는 모든 검사를 가져옵니다.

예제 3: 대상 개체에 대한 경로를 사용하여 검사 가져오기

PS:> Get-SqlAssessmentItem SQLSERVER:\SQL\localhost\default

   Target: [LOCAL]

ID                             ON      Name                                     Origin                                  
--                             --      ----                                     ------                                  
TF1204                         True    TF 1204 returns deadlock information     Microsoft Ruleset 0.1.202                   
BlackboxTrace                  True    Blackbox trace is configured and running Microsoft Ruleset 0.1.202                   
HintsStatistics                True    Hints are being used                     Microsoft Ruleset 0.1.202                   
PlansUseRatio                  True    Amount of single use plans in cache i... Microsoft Ruleset 0.1.202                   
TempDBFilesAutoGrowth          True    Some TempDB data files have different... Microsoft Ruleset 0.1.202                   
CpuUtil90                      True    CPU usage over 90%                       Microsoft Ruleset 0.1.202  
...

이 예제에서는 현재 컴퓨터에서 실행되는 SQL Server 기본 instance 사용할 수 있는 모든 검사를 가져옵니다.

예제 4: 적용된 사용자 지정 구성을 사용하여 검사 가져오기

PS:> Get-SqlDatabase master -ServerInstance . |
     Get-SqlAssessmentItem -Configuration C:\rulesetA.json, D:\rulesetB.json

   Target: [LOCAL]

ID                             ON      Name                                     Origin                                  
--                             --      ----                                     ------                                  
TF1204                         False   TF 1204 returns deadlock information     Microsoft Ruleset 0.1.202                   
BlackboxTrace                  True    Blackbox trace is configured and running Microsoft Ruleset 0.1.202                   
HintsStatistics                True    Hints are being used                     Microsoft Ruleset 0.1.202                   
PlansUseRatio                  True    Amount of single use plans in cache i... Microsoft Ruleset 0.1.202                   
TempDBFilesAutoGrowth          False   Some TempDB data files have different... Microsoft Ruleset 0.1.202                   
CpuUtil90                      True    CPU usage over 90%                       Microsoft Ruleset 0.1.202                   
SomeCustomCheck                True    Some custom check                        Ruleset A 1.0                           
AnotherCustomCheck             True    Another custom check                     Ruleset B 1.0
...

이 예제에서는 지정된 JSON 파일에서 가져온 적용된 사용자 지정 구성을 사용하여 사용 가능한 모든 검사를 가져옵니다. 사용자 지정을 수행하는 방법을 알아보려면 Github의 SQL 평가 샘플 폴더 를 방문하세요.

예제 5: localhost의 모든 인스턴스에 대한 검사 가져오기

PS:> Get-SqlInstance -ServerInstance localhost | Get-SqlAssessmentItem

   Target: [LOCAL]

ID                             ON      Name                                     Origin                                  
--                             --      ----                                     ------                                  
TF1204                         True    TF 1204 returns deadlock information     Microsoft Ruleset 0.1.202               
BlackboxTrace                  True    Blackbox trace is configured and running Microsoft Ruleset 0.1.202               
CpuUtil90                      True    CPU usage over 90%                       Microsoft Ruleset 0.1.202

   Target: [LOCAL\INSTANCE1]

ID                             ON      Name                                     Origin                                  
--                             --      ----                                     ------                                  
HintsStatistics                True    Hints are being used                     Microsoft Ruleset 0.1.202             
PlansUseRatio                  True    Amount of single use plans in cache i... Microsoft Ruleset 0.1.202               
TempDBFilesAutoGrowth          True    Some TempDB data files have different... Microsoft Ruleset 0.1.202               
CpuUtil90                      True    CPU usage over 90%                       Microsoft Ruleset 0.1.202
...

이 예제에서는 파이프라인을 통해 SQL Server 인스턴스 집합을 수락하는 Get-SqlAssessmentItem cmdlet을 보여 줍니다.

예제 6: 이름이 숫자로 끝나는 모든 인스턴스에 대한 검사 가져오기

PS:> Get-SqlInstance -ServerInstance localhost | Where { $_.Name -Match '.*\d+' } | Get-SqlAssessmentItem

   Target: [LOCAL\INSTANCE1]

ID                             ON      Name                                     Origin                                  
--                             --      ----                                     ------                                  
HintsStatistics                True    Hints are being used                     Microsoft Ruleset 0.1.202               
PlansUseRatio                  True    Amount of single use plans in cache i... Microsoft Ruleset 0.1.202             
TempDBFilesAutoGrowth          True    Some TempDB data files have different... Microsoft Ruleset 0.1.202               
CpuUtil90                      True    CPU usage over 90%                       Microsoft Ruleset 0.1.202
...

이 예제에서는 파이프라인을 통해 SQL Server 인스턴스 집합을 수락하는 Get-SqlAssessmentItem cmdlet을 보여 줍니다. 이름이 숫자로 끝나는 인스턴스만 처리됩니다.

예제 7: 경로별 데이터베이스 검사 가져오기

PS:> Get-SqlAssessmentItem SQLSERVER:\SQL\localhost\default\Databases\master


   TargetObject: [master]

ID                             ON      Name                                     Origin                    
--                             --      ----                                     ------                    
AutoCreateStats                True    Auto-Create Statistics should be on      Microsoft Ruleset 0.1.202 
HintsUsageInModules            False   Hints usage in modules                   Microsoft Ruleset 0.1.202 
FullBackup                     True    Full backup is missed or outdated        Microsoft Ruleset 0.1.202 
DuplicateIndexes               True    Duplicate Indexes                        Microsoft Ruleset 0.1.202 
RedundantIndexes               True    Redundant Indexes                        Microsoft Ruleset 0.1.202 
...

이 예제에서는 SQL Server 데이터베이스에 대한 경로를 수락하는 Get-SqlAssessmentItem cmdlet을 보여 줍니다.

예제 8: 데이터베이스에 대한 높은 심각도 검사 가져오기

PS:> cd SQLSERVER:\SQL\localhost\default\Databases\master
PS:> Get-SqlAssessmentItem -MinSeverity High

이 예제에서는 Get-SqlAssessmentItem이 master 데이터베이스에 대해 심각도가 높은 사용 가능한 검사를 반환하는 것을 보여 줍니다. 현재 PowerShell 공급자 위치를 대상으로 허용합니다.

예제 9: 데이터베이스에 대한 높은 심각도 검사 가져오기

PS:> $db = Get-SqlDatabase master -ServerInstance localhost
PS:> Get-SqlAssessmentItem $db -MinSeverity High

이 예제에서는 Get-SqlAssessmentItem이 master 데이터베이스에 대해 심각도가 높은 사용 가능한 검사를 반환하는 것을 보여 줍니다.

예제 10: 태그별 검사 가져오기

PS:> Get-SqlDatabase -ServerInstance . | Get-SqlAssessmentItem -Check Backup


   TargetObject: [master]

ID                             ON      Name                                     Origin                    
--                             --      ----                                     ------                    
FullBackup                     True    Full backup is missed or outdated        Microsoft Ruleset 0.1.202 


   TargetObject: [msdb]

ID                             ON      Name                                     Origin                    
--                             --      ----                                     ------                    
FullBackup                     True    Full backup is missed or outdated        Microsoft Ruleset 0.1.202

이 예제에서는 기본 로컬 SQL Server instance 모든 데이터베이스에 대한 모든 백업 관련 검사를 반환하는 Get-SqlAssessmentItem cmdlet을 보여 줍니다.

예제 11: 대화형으로 선택한 검사 실행

PS:> $serverInstance = Get-SqlInstance -ServerInstance '(local)'
PS:> $checks = Get-SqlAssessmentItem $serverInstance | Select Id, Description | Out-GridView -PassThru
PS:> Invoke-SqlAssessment $serverInstance -Check $checks

    TargetPath : Server[@Name='LOCAL']

Sev. Message                                                            Check ID               Origin                   
---- -------                                                            --------               ------                   
Info Enable trace flag 834 to use large-page allocations to improve     TF834                  Microsoft Ruleset 0.1.202
     analytical and data warehousing workloads.                                                                         
Low  Detected deprecated or discontinued feature uses: String literals  DeprecatedFeatures     Microsoft Ruleset 0.1.202
     as column aliases, syscolumns, sysusers, SET FMTONLY ON, XP_API,                                                   
     Table hint without WITH, More than two-part column name. We                                                        
     recommend to replace them with features actual for SQL Server                                                      
     version 14.0.1000.

이 예제의 두 번째 줄에서는 $serverInstance 대한 검사를 가져오고 그 중 일부를 대화형으로 선택하는 방법을 보여 있습니다. 선택한 항목은 배열 변수에 저장되며 Invoke-SqlAssessment cmdlet에 대한 입력으로 사용할 수 있습니다. 이 경우 평가 프로세스 중에 선택한 검사만 실행됩니다.

예제 12: 자격 증명을 명시적으로 지정

PS> $cred = Get-Credential

PowerShell credential request
Enter your credentials.
User: Administrator
Password for user Administrator: ********

PS> $db = Get-SqlDatabase master -ServerInstance 10.0.3.118 -Credential $cred
PS> Get-SqlAssessmentItem $db

   TargetObject: [master]

ID                             ON      Name                                     Origin                    
--                             --      ----                                     ------                    
AutoCreateStats                True    Auto-Create Statistics should be on      Microsoft Ruleset 0.1.202 
FullBackup                     True    Full backup is missed or outdated        Microsoft Ruleset 0.1.202 
DuplicateIndexes               True    Duplicate Indexes                        Microsoft Ruleset 0.1.202 
RedundantIndexes               True    Redundant Indexes                        Microsoft Ruleset 0.1.202 
...

이 예제에서는 명시적으로 지정된 자격 증명을 사용하여 SQL 평가 검사 목록을 가져오는 방법을 보여 줍니다.

예제 13: Azure VM instance SQL Server 대한 SQL 평가 규칙 목록 가져오기

PS> Connect-AzAccount
PS> Set-Subscription My-Pay-As-You-Go
PS> $cred = Get-Credential

PowerShell credential request
Enter your credentials.
User: Administrator
Password for user Administrator: ********

PS> $inst = Get-SqlInstance -ServerInstance 10.0.3.118 -Credential $cred
PS> Get-SqlAssessmentItem $inst

   TargetObject: [ContosoAzureSql]

ID                             ON      Name                                     Origin                    
--                             --      ----                                     ------                    
HintsStatistics                True    Hints are being used                     Microsoft Ruleset 0.1.202               
PlansUseRatio                  True    Amount of single use plans in cache i... Microsoft Ruleset 0.1.202             
TempDBFilesAutoGrowth          True    Some TempDB data files have different... Microsoft Ruleset 0.1.202 
AzSqlVmSize                    True    VM size is not memory-optimized          Microsoft Ruleset 0.1.202 
...

이 예제에서는 Azure VM instance 특정 SQL Server 적용할 수 있는 규칙 목록을 가져오는 방법을 보여줍니다.

활성 Azure 구독 연결을 사용하면 Azure 관련 검사를 사용할 수 있습니다(이 예제에서는 AzSqlVmSize). 첫 번째 줄은 Azure 계정에 연결하여 Azure Resource Graph 데이터를 가져옵니다. 두 번째 줄은 선택 사항입니다.

이러한 검사를 실행하려면 SQL 평가에 Az.ResourceGraph 모듈이 필요합니다.

매개 변수

-Check

하나 이상의 검사, 검사 ID 또는 태그.

모든 검사 개체에 대해 Get-SqlAssessmentItem은 입력 개체를 지원하는 경우 해당 검사 반환합니다.

모든 검사 ID에 대해 Get-SqlAssessmentItem은 입력 개체를 지원하는 경우 해당 검사 반환합니다.

태그의 경우 Get-SqlAssessmentItem 은 해당 태그가 포함된 검사를 반환합니다.

Type:String[]
Position:Named
Default value:None
Required:False
Accept pipeline input:False
Accept wildcard characters:False

-Configuration

사용자 지정 구성을 포함하는 파일의 경로를 지정합니다. 사용자 지정 파일은 지정된 순서로 기본 구성에 적용됩니다. scope 이 cmdlet 호출로만 제한됩니다.

Type:PSObject
Position:Named
Default value:None
Required:False
Accept pipeline input:False
Accept wildcard characters:False

-FlattenOutput

이 cmdlet은 Microsoft.SqlServer.Management.Assessment.Cmdlets.AssessmentNote 대신 Microsoft.SqlServer.Management.Assessment.Cmdlets.AssessmentNote 형식의 간단한 개체를 생성 한다는 것을 나타냅니다.

Type:SwitchParameter
Position:Named
Default value:None
Required:False
Accept pipeline input:False
Accept wildcard characters:False

-InputObject

SQL Server 개체 또는 이러한 개체의 경로를 지정합니다. cmdlet은 이 개체에 대한 적절한 검사를 반환합니다. 이 매개 변수를 생략하면 현재 위치가 입력 개체로 사용됩니다. 현재 위치가 지원되는 SQL Server 개체가 아니면 cmdlet에서 오류를 알 수 있습니다.

Type:PSObject
Aliases:Target
Position:10
Default value:None
Required:False
Accept pipeline input:True
Accept wildcard characters:False

-MinSeverity

검사를 찾을 수 있는 최소 심각도 수준을 지정합니다. 예를 들어 중간, 낮음 또는 정보 수준에 대한 검사는 -MinSeverity High일 때 반환되지 않습니다.

Type:SeverityLevel
Aliases:Severity
Accepted values:Information, Low, Medium, High
Position:Named
Default value:Information
Required:False
Accept pipeline input:False
Accept wildcard characters:False

입력

System.String[]

Microsoft.SqlServer.Management.Smo.SqlSmoObject[]

출력

Microsoft.SqlServer.Management.Assessment.ICheck