{ "metadata": { "kernelspec": { "name": "powershell", "display_name": "PowerShell" }, "language_info": { "name": "powershell", "codemirror_mode": "shell", "mimetype": "text/x-sh", "file_extension": ".ps1" } }, "nbformat_minor": 2, "nbformat": 4, "cells": [ { "cell_type": "markdown", "source": [ "# Prerequisites and Initial Setup\n", "\n", "Most of the notebooks in the Azure SQL Hybrid Cloud Toolkit use either Microsoft PowerShell or Python for their script functionality. This notebook will perform the local machine configuration necessary to execute the various notebooks successfully.\n", "\n", "## Microsoft PowerShell Version\n", "\n", "Some notebooks use a [PowerShell Notebook kernel](https://youtu.be/BhbiAINQBYE) that requires PS v5.1 or greater." ], "metadata": { "azdata_cell_guid": "26e96caf-0241-43ee-a44b-9743265919d4" } }, { "cell_type": "code", "source": [ "# Check that PowerShell >= v5.1 and Azure Command Line Interface (Az CLI) are installed\r\n", "if ($PSVersionTable.PSVersion.Major -lt 5)\r\n", "{\r\n", " Write-Warning \"Some notebooks require a greater version of PowerShell.\"\r\n", "}\r\n", "else {\r\n", " $psVersion = $PSVersionTable.PSVersion.ToString()\r\n", " Write-Output \"Found PS version... $psVersion\"\r\n", "}" ], "metadata": { "azdata_cell_guid": "3ce85087-8cd5-49fc-8e67-00c996e95fbe", "tags": [] }, "outputs": [], "execution_count": null }, { "cell_type": "markdown", "source": [ "## PowerShellGet and PowerShell Gallery Modules\n", "\n", "If you do not have PS Nuget provider installed, then please see [Installing PowerShellGet](https://docs.microsoft.com/en-us/powershell/scripting/gallery/installing-psget). The initial setup for the PowerShellGet module may require elevated permissions and is recommended to be done in a separate PowerShell command prompt. \n", "\n", "The modules required by the toolkit are available on the [PowerShell Gallery](https://www.powershellgallery.com/), a central repository for sharing PS modules and scripts. The setup code in this notebook will create a temporary call to install required PowerShell modules in the current user scope. If the modules have not already been installed, the following code will install them with a new gallery registration setup as trusted to enable installation of modules without prompting. After installing the modules, the gallery registration will be removed.\n", "\n", "| Module | Description |\n", "| --- | --- |\n", "| dbatools | Provides high-level cmdlets that perform SQL management operations. These CMDLETs have extensive validation tests and configuration options. |\n", "| Az.Accounts | Provides cmdlets to configure subscription and account settings |\n", "| Az.Resources | Provides cmdlets to access and provision Microsoft Azure resources |\n", "| Az.Storage | Provides cmdlets to simplify configuration and access to Azure storage resources |\n", "| Az.Network | Networking cmdlets for Azure Resource Manager |\n", "| Az.Compute | Compute service cmdlets |\n", "| AnyBox | Provides GUI input box support (Windows only) |\n", "| SqlServer | Provides cmdlets to automate database development and server administration, as well as both multidimensional and tabular cube processing |" ], "metadata": { "azdata_cell_guid": "836a217a-b348-420e-b525-e06580f717b0" } }, { "cell_type": "code", "source": [ "# need to check if nuget package provider is installed\r\n", "$nuget=(Get-PackageProvider -Name NuGet)\r\n", "\r\n", "if (!$nuget)\r\n", "{\r\n", " Get-PackageProvider -Name NuGet -ForceBootstrap\r\n", " Import-PackageProvider -Name NuGet -RequiredVersion 2.8.5.201\r\n", "}\r\n", "\r\n", "#temporary reposistory registration\r\n", "Register-PSRepository -Name PSGalleryTemp -SourceLocation https://www.powershellgallery.com/api/v2/ -PublishLocation https://www.powershellgallery.com/api/v2/package/ -ScriptSourceLocation https://www.powershellgallery.com/api/v2/items/psscript/ -ScriptPublishLocation https://www.powershellgallery.com/api/v2/package/ -InstallationPolicy Trusted -PackageManagementProvider NuGet\r\n", "\r\n", "#required modules for this notebook\r\n", "$requiredModules = @(\"dbatools\", \"Az.Accounts\", \"Az.Resources\", \"Az.Storage\", \"Az.Network\", \"Az.Compute\", \"AnyBox\",\"SqlServer\")\r\n", "\r\n", "#check each module and install if necessary\r\n", "foreach ($moduleName in $requiredModules) {\r\n", " if (!(Get-Module -ListAvailable -Name $moduleName)) {\r\n", " Install-Module -Name $moduleName -Scope CurrentUser -AllowClobber -Repository PSGalleryTemp\r\n", " }\r\n", "} \r\n", "\r\n", "#remove temporary gallery registration\r\n", "Unregister-PSRepository -Name PSGalleryTemp\r\n", "\r\n", "# Output any missing modules\r\n", "foreach ($moduleName in $requiredModules) {\r\n", " $module = Get-InstalledModule $moduleName\r\n", " if (!($module)) {\r\n", " Write-Warning \"The specified module is not installed...$moduleName\"\r\n", " }\r\n", " else{\r\n", " $module\r\n", " }\r\n", "} " ], "metadata": { "azdata_cell_guid": "e9c3177c-fde7-4c62-8220-62622620f9b4" }, "outputs": [], "execution_count": null }, { "cell_type": "markdown", "source": [ "## SQL Assessment cmdlets and SMO extension\n", "\n", "SQL Assessment API is part of the SQL Server Management Objects (SMO) and can be used with the SQL Server PowerShell module. Because installing the modules may require a local Administrator account's permission, it cannot be done automatically with this Notebook. The **Assessments** Notebooks require the following:\n", "\n", "- [Install SMO](https://docs.microsoft.com/en-us/sql/relational-databases/server-management-objects-smo/installing-smo?view=sql-server-ver15)\n", "- [Install SQL Server PowerShell module](https://docs.microsoft.com/en-us/sql/powershell/download-sql-server-ps-module?view=sql-server-ver15)\n", "\n", "## Compatibility Assessment Tool - Data Migration Assistant\n", "\n", "The Compatibility Assessment Notebook requires the Data Migration Assistant tool to be installed in order to execute. The installation link would be [Data Migration Assistant download](https://www.microsoft.com/en-us/download/confirmation.aspx?id=53595)\n", "\n", "With version 2.1 and above, when installation of Data Migration Assistant is successful, it will install dmacmd.exe in _%ProgramFiles%\\\\Microsoft Data Migration Assistant_ folder." ], "metadata": { "azdata_cell_guid": "1b49a7e5-a773-4104-8f88-bd2ea3c806a3" } }, { "cell_type": "markdown", "source": [ "## Azure CLI\n", "\n", "Some notebooks also require the latest version of Azure command line interface (CLI). To install, see [https://aka.ms/installazurecliwindows](https://aka.ms/installazurecliwindows). Update instructions can be found at [https://aka.ms/doc/UpdateAzureCliMsi](https://aka.ms/doc/UpdateAzureCliMsi)" ], "metadata": { "azdata_cell_guid": "e032f30b-5ca7-47bf-bf5e-1bd36d2763f8" } }, { "cell_type": "code", "source": [ "# Check for Azure CLI\r\n", "$azCli = (az --version)\r\n", "if ($azCli) { \r\n", " $azVersion = $azCli[0].Split()[-1]\r\n", " if ($azVersion -eq \"*\") {\r\n", " $azVersion = $azCli[0].Split()[-2]\r\n", " }\r\n", " Write-Output \"Found Az CLI version... $azVersion\"\r\n", "}\r\n", "else {\r\n", " Write-Warning \"Some notebooks require the Az CLI. Please install if to run these notebooks.\"\r\n", "}" ], "metadata": { "azdata_cell_guid": "398e7abe-5a60-477c-8d04-0545389614b0" }, "outputs": [], "execution_count": null }, { "cell_type": "markdown", "source": [ "## PowerShell ADS Extension\n", "\n", "It may also be useful to install the official release of the PowerShell ADS extension by following the steps in the [Azure Data Studio documentation](vscode-webview://extensioneditor/electron-browser/docs.microsoft.com/en-us/sql/azure-data-studio/extensions). Installing this extension is optional but will enable syntax highlighting and intellisense within ADS. \n", "\n", "In the Extensions pane, search for \"PowerShell\" extension and install it there. It is also possible to install a VSIX package from the [PowerShell extension's Releases page](https://github.com/PowerShell/vscode-powershell/releases) through the command line:\n", "\n", "`azuredatastudio --install-extension PowerShell-.vsix`" ], "metadata": { "azdata_cell_guid": "1b4aadb8-753b-43e4-8582-d05e51edbb7f" } }, { "cell_type": "code", "source": [ "# azuredatastudio --install-extension PowerShell-v2020.9.0-preview.vsix # Uncomment to install a specific version" ], "metadata": { "azdata_cell_guid": "86ff5c4f-bf3b-4ca0-aba0-edf592106958" }, "outputs": [], "execution_count": null } ] }