mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-16 10:58:30 -05:00
Cavonac/sqlassessment (#13900)
* Update sql-server-assessment.ipynb code to query the assessment results removed the registered servers to avoid confusion * update link
This commit is contained in:
@@ -2,7 +2,8 @@
|
|||||||
"metadata": {
|
"metadata": {
|
||||||
"kernelspec": {
|
"kernelspec": {
|
||||||
"name": "powershell",
|
"name": "powershell",
|
||||||
"display_name": "PowerShell"
|
"display_name": "PowerShell",
|
||||||
|
"language": "powershell"
|
||||||
},
|
},
|
||||||
"language_info": {
|
"language_info": {
|
||||||
"name": "powershell",
|
"name": "powershell",
|
||||||
@@ -19,16 +20,15 @@
|
|||||||
"source": [
|
"source": [
|
||||||
"# SQL Server Assessment Tool\n",
|
"# SQL Server Assessment Tool\n",
|
||||||
"\n",
|
"\n",
|
||||||
"Unlike other notebooks, **do not execute all cells of this notebook!** \n",
|
"Performs a best-practices assessment on a local SQL Server Instance. A single assessment may take some time, so fill out the variables and execute the cell that matches the desired environment to perform the assessment needed.\n",
|
||||||
"\n",
|
|
||||||
"A single assessment may take awhile so fill out the variables and execute the cell that matches the desired environment to perform the assessment needed. Only one of these cells needs to be executed after the variables are defined.\n",
|
|
||||||
"\n",
|
"\n",
|
||||||
"## Notebook Variables\n",
|
"## Notebook Variables\n",
|
||||||
"\n",
|
"\n",
|
||||||
"| Line | Variable | Description |\n",
|
"| Line | Variable | Description | Example |\n",
|
||||||
"| ---- | -------- | ----------- |\n",
|
"| --- | --- | --- | --- |\n",
|
||||||
"| 1 | ServerInstance | Name of the SQL Server instance |\n",
|
"| 1 | ServerInstance | Name of the SQL Server instance | MSSQLSERVER |\n",
|
||||||
"| 2 | Group | (Optional) Name of the server group, if known | "
|
"| 2 | OutputDb | New or existing database to place assessment results in | DB1 |\n",
|
||||||
|
"| 3 | OutputTable | Target table to place assessment results (for a clean assessment, use a new table name) | AssessmentResults |"
|
||||||
],
|
],
|
||||||
"metadata": {
|
"metadata": {
|
||||||
"azdata_cell_guid": "86ecfb01-8c38-4a99-92a8-687d8ec7f4b0"
|
"azdata_cell_guid": "86ecfb01-8c38-4a99-92a8-687d8ec7f4b0"
|
||||||
@@ -38,7 +38,8 @@
|
|||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"source": [
|
"source": [
|
||||||
"$ServerInstance = \"\"\r\n",
|
"$ServerInstance = \"\"\r\n",
|
||||||
"$Group = \"\""
|
"$OutputDb = \"\"\r\n",
|
||||||
|
"$OutputTable = \"\""
|
||||||
],
|
],
|
||||||
"metadata": {
|
"metadata": {
|
||||||
"azdata_cell_guid": "db21129e-9bda-4db9-8d61-d2b264a3cad8"
|
"azdata_cell_guid": "db21129e-9bda-4db9-8d61-d2b264a3cad8"
|
||||||
@@ -49,12 +50,12 @@
|
|||||||
{
|
{
|
||||||
"cell_type": "markdown",
|
"cell_type": "markdown",
|
||||||
"source": [
|
"source": [
|
||||||
"## Notebook Steps\r\n",
|
"## Notebook Steps\n",
|
||||||
"1. Ensure that the proper APIs and modules are installed per the <a href=\"../prereqs.ipynb\">prerequisites</a> notebook\r\n",
|
"\n",
|
||||||
"2. Define a service instance and group corresponding to the SQL Server instances to be assessed\r\n",
|
"1. Ensure that the proper APIs and modules are installed per the <a href=\"..\\prereqs.ipynb\">prerequisites</a> notebook\n",
|
||||||
"3. Choose an example below that corresponds to the appropriate task\r\n",
|
"2. Define above variables corresponding to the SQL Server instance to be assessed\n",
|
||||||
"4. Execute only that example's code block and wait for results\r\n",
|
"3. Run the notebook to list the Assessment rules being considered, perform the assessment, and list the results\n",
|
||||||
"5. Fix any recommended issues and rerun Assessment API until clear"
|
"4. Fix any warnings and rerun Assessment API until clear by reviewing the results table"
|
||||||
],
|
],
|
||||||
"metadata": {
|
"metadata": {
|
||||||
"azdata_cell_guid": "541f6806-f8d2-4fc5-a8fb-6d42947d1a64"
|
"azdata_cell_guid": "541f6806-f8d2-4fc5-a8fb-6d42947d1a64"
|
||||||
@@ -63,8 +64,9 @@
|
|||||||
{
|
{
|
||||||
"cell_type": "markdown",
|
"cell_type": "markdown",
|
||||||
"source": [
|
"source": [
|
||||||
"### Example 1 Get-SqlInstance\r\n",
|
"### Retrieve Checks for SQL Instance\n",
|
||||||
"Pipe the output of the Get-SqlInstance cmdlet to the _Get-SqlAssessmentItem_ cmdlet to pass the instance object to it to perform an assessment on the entire instance. "
|
"\n",
|
||||||
|
"Pipe the output of the Get-SqlInstance cmdlet to the _Get-SqlAssessmentItem_ cmdlet to get the list of checks and their status. These results ought to display a list of rules for a default assessment."
|
||||||
],
|
],
|
||||||
"metadata": {
|
"metadata": {
|
||||||
"azdata_cell_guid": "c6f94c36-0566-4963-acb8-4a419758d26e"
|
"azdata_cell_guid": "c6f94c36-0566-4963-acb8-4a419758d26e"
|
||||||
@@ -84,49 +86,8 @@
|
|||||||
{
|
{
|
||||||
"cell_type": "markdown",
|
"cell_type": "markdown",
|
||||||
"source": [
|
"source": [
|
||||||
"### Example 2 - Get-Item\r\n",
|
"### Export Assessment to SQL Table\n",
|
||||||
"Get a list of available databases in the instance using the _Get-Item_ cmdlet and pipe it to _Get-SqlAssessmentItem_. "
|
"\n",
|
||||||
],
|
|
||||||
"metadata": {
|
|
||||||
"azdata_cell_guid": "30bcf8ed-cfd4-4e3b-b634-acdafab13437"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"cell_type": "code",
|
|
||||||
"source": [
|
|
||||||
"Get-Item SQLSERVER:\\SQL\\$serverInstance\\default | Get-SqlAssessmentItem"
|
|
||||||
],
|
|
||||||
"metadata": {
|
|
||||||
"azdata_cell_guid": "4525cbe7-719a-4cc3-8ebd-5279731c3979"
|
|
||||||
},
|
|
||||||
"outputs": [],
|
|
||||||
"execution_count": null
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"cell_type": "markdown",
|
|
||||||
"source": [
|
|
||||||
"### Example 3 - Get-SqlDatabase\r\n",
|
|
||||||
"Or, use the _Get-SqlDatabase_ cmdlet without specifying a name to get a full list of database objects."
|
|
||||||
],
|
|
||||||
"metadata": {
|
|
||||||
"azdata_cell_guid": "def37aca-fe6e-48ad-9794-09fd9ba77740"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"cell_type": "code",
|
|
||||||
"source": [
|
|
||||||
"Get-SqlDatabase -ServerInstance $serverInstance | Get-SqlAssessmentItem"
|
|
||||||
],
|
|
||||||
"metadata": {
|
|
||||||
"azdata_cell_guid": "da57fa74-86b1-4d2f-a419-4035c10f0d3a"
|
|
||||||
},
|
|
||||||
"outputs": [],
|
|
||||||
"execution_count": null
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"cell_type": "markdown",
|
|
||||||
"source": [
|
|
||||||
"### Example 4 - Export Assessment to SQL Table\r\n",
|
|
||||||
"Invoke assessment for the instance and save the results to a SQL table by piping the output of the _Get-SqlInstance_ cmdlet to the _Invoke-SqlAssessment_ cmdlet. The results are piped to the _Write-SqlTableData_ cmdlet. The _Invoke-Assessment_ cmdlet is run with the -**FlattenOutput** parameter in this example. This parameter makes the output suitable for the _Write-SqlTableData_ cmdlet. The latter raises an error if the parameter is omitted."
|
"Invoke assessment for the instance and save the results to a SQL table by piping the output of the _Get-SqlInstance_ cmdlet to the _Invoke-SqlAssessment_ cmdlet. The results are piped to the _Write-SqlTableData_ cmdlet. The _Invoke-Assessment_ cmdlet is run with the -**FlattenOutput** parameter in this example. This parameter makes the output suitable for the _Write-SqlTableData_ cmdlet. The latter raises an error if the parameter is omitted."
|
||||||
],
|
],
|
||||||
"metadata": {
|
"metadata": {
|
||||||
@@ -138,7 +99,7 @@
|
|||||||
"source": [
|
"source": [
|
||||||
"Get-SqlInstance -ServerInstance $serverInstance |\r\n",
|
"Get-SqlInstance -ServerInstance $serverInstance |\r\n",
|
||||||
"Invoke-SqlAssessment -FlattenOutput |\r\n",
|
"Invoke-SqlAssessment -FlattenOutput |\r\n",
|
||||||
"Write-SqlTableData -ServerInstance $serverInstance -DatabaseName SQLAssessmentDemo -SchemaName Assessment -TableName Results -Force"
|
"Write-SqlTableData -ServerInstance $serverInstance -DatabaseName $outputDb -SchemaName Assessment -TableName $OutputTable -Force"
|
||||||
],
|
],
|
||||||
"metadata": {
|
"metadata": {
|
||||||
"azdata_cell_guid": "28ce8df2-1da8-4462-8e91-62646642d4b1"
|
"azdata_cell_guid": "28ce8df2-1da8-4462-8e91-62646642d4b1"
|
||||||
@@ -149,56 +110,36 @@
|
|||||||
{
|
{
|
||||||
"cell_type": "markdown",
|
"cell_type": "markdown",
|
||||||
"source": [
|
"source": [
|
||||||
"### Example 5 - SQL Server (SSMS) Locally Registered Servers\r\n",
|
"### Display the Results\n",
|
||||||
"To gather locally saved SQL registered servers, use the SQL Server PowerShell module installed from the [Pre-requisites notebook](..\\prereqs.ipynb). "
|
"\n",
|
||||||
|
"Use _Invoke-SqlCmd_ cmdlet to execute a short query to display the assessment results in this notebook in a custom format."
|
||||||
],
|
],
|
||||||
"metadata": {
|
"metadata": {
|
||||||
"azdata_cell_guid": "3a14a231-2ab3-45db-9afa-fbd369f4ec0f"
|
"azdata_cell_guid": "44bb8b3f-b456-43b4-ba2f-ae22c715a984"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"source": [
|
"source": [
|
||||||
"Import-Module SqlServer\r\n",
|
"$q = \"SELECT TOP (1000) * FROM [$outputDb].[Assessment].[$OutputTable]\"\r\n",
|
||||||
"$RegisteredServers = Get-ChildItem SQLSERVER:\\SQLRegistration -Recurse | Where-Object {$_.IsLocal -eq $True}\r\n",
|
"$results = Invoke-SqlCmd -Query $q -ServerInstance $ServerInstance\r\n",
|
||||||
"$RegisteredServers.Refresh() \r\n",
|
"foreach ($result in $results)\r\n",
|
||||||
"$RegisteredServers | Format-List -Property *"
|
"{\r\n",
|
||||||
],
|
" Write-Output \"----------------------------------------------------------\"\r\n",
|
||||||
"metadata": {
|
" Write-Output $result.CheckName\r\n",
|
||||||
"azdata_cell_guid": "c373d5c0-3eaa-4196-8cd4-2e7d9d1896a1",
|
" if ($result.Severity -ne \"Information\")\r\n",
|
||||||
"tags": []
|
" {\r\n",
|
||||||
},
|
" Write-Warning $result.Message\r\n",
|
||||||
"outputs": [],
|
" }\r\n",
|
||||||
"execution_count": null
|
" else \r\n",
|
||||||
},
|
" {\r\n",
|
||||||
{
|
" Write-Output $result.Message\r\n",
|
||||||
"cell_type": "markdown",
|
" }\r\n",
|
||||||
"source": [
|
" Write-Output $result.HelpLink\r\n",
|
||||||
"### Example 5 - Specifying a Central Management Server\r\n",
|
|
||||||
"Many large organizations use [Registered Servers](https://docs.microsoft.com/en-us/sql/ssms/register-servers/register-servers) to organize their networks within editors like SSMS or ADS. To take advantage of running the SQL Server Assessment API against all or a specific Registered Server Group, specify the CMS instance below. \r\n",
|
|
||||||
"\r\n",
|
|
||||||
"\r\n",
|
|
||||||
"\r\n",
|
|
||||||
"Take advantage of the [dbatools CMS module](https://dbatools.io/cms/) for this task. "
|
|
||||||
],
|
|
||||||
"metadata": {
|
|
||||||
"azdata_cell_guid": "cd3b800e-003f-432c-88aa-5738aba11378"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"cell_type": "code",
|
|
||||||
"source": [
|
|
||||||
"# Get a list of all servers stored on the CMS instance \r\n",
|
|
||||||
"# Note that this list is pipable to all dbatools commands\r\n",
|
|
||||||
"\r\n",
|
|
||||||
"if($SqlInstance -And $Group){\r\n",
|
|
||||||
" Get-DbaRegServer -SqlInstance $SqlInstance -Group $Group\r\n",
|
|
||||||
"}else{\r\n",
|
|
||||||
" Get-DbaRegServer -SqlInstance $SqlInstance\r\n",
|
|
||||||
"}"
|
"}"
|
||||||
],
|
],
|
||||||
"metadata": {
|
"metadata": {
|
||||||
"azdata_cell_guid": "4a7bd412-5099-47b4-a737-455e01b0c172"
|
"azdata_cell_guid": "5bab466f-2ea0-4c3a-9ac1-923ac1548dd3"
|
||||||
},
|
},
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"execution_count": null
|
"execution_count": null
|
||||||
|
|||||||
Reference in New Issue
Block a user