|
| 1 | +--- |
| 2 | +services: Azure Arc-enabled SQL Server |
| 3 | +platforms: Azure |
| 4 | +author: anosov1960 |
| 5 | +ms.author: sashan |
| 6 | +ms.date: 4/6/2023 |
| 7 | +--- |
| 8 | + |
| 9 | + |
| 10 | +# Overview |
| 11 | + |
| 12 | +This script provides a scalable solution to uninstall Azure extension for SQL Server on a specific Arc-enabled server, |
| 13 | +all Arc-enabled servers in a specific resource group, specific subscription, a list of subscriptions or the entire account. |
| 14 | +You can specify a single subscription to scan, or provide a list of subscriptions as a .CSV file. |
| 15 | + |
| 16 | +# Prerequisites |
| 17 | + |
| 18 | +- You must have at least a *Contributor* role in each subscription you modify. |
| 19 | +- The Azure extension for SQL Server is updated to version 1.1.2230.58 or newer. |
| 20 | + |
| 21 | +# Launching the script |
| 22 | + |
| 23 | +The script accepts the following command line parameters: |
| 24 | + |
| 25 | +| **Parameter** | **Value** | **Description** | |
| 26 | +|:--|:--|:--| |
| 27 | +|-SubId|subscription_id *or* a file_name|Optional: subscription id or a .csv file with the list of subscriptions<sup>1</sup>. | |
| 28 | +|-ResourceGroup |resource_group_name|Optional: Limit the scope to a specific resource group| |
| 29 | +|-MachineName |machine_name|Optional: Limit the scope to a specific machine| |
| 30 | +|-All|\$True or \$False (default)|Optional. Uninstall Azure extension on all Arc-enabled servers in all subscriptions you have contributor access to.| |
| 31 | + |
| 32 | +<sup>1</sup>You can create a .csv file using the following command and then edit to remove the subscriptions you don't want to scan. |
| 33 | +```PowerShell |
| 34 | +Get-AzSubscription | Export-Csv .\mysubscriptions.csv -NoTypeInformation |
| 35 | +``` |
| 36 | + |
| 37 | +## Example 1 |
| 38 | + |
| 39 | +The following command will scan all the subscriptions to which the user has contributor access to, and uninstall Azure extension for SQL Server on all Arc-enabled servers where it is installed. |
| 40 | + |
| 41 | +```PowerShell |
| 42 | +.\uninstall-azure-extension-for-sql-server.ps1 -All $True |
| 43 | +``` |
| 44 | + |
| 45 | +## Example 2 |
| 46 | + |
| 47 | +The following command will scan the subscription `<sub_id>` and uninstall Azure extension for SQL Server on all Arc-enabled servers where it is installed. |
| 48 | + |
| 49 | +```PowerShell |
| 50 | +.\uninstall-azure-extension-for-sql-server.ps1 -SubId <sub_id> |
| 51 | +``` |
| 52 | + |
| 53 | +## Example 3 |
| 54 | + |
| 55 | +The following command will scan resource group <resource_group_name> in the subscription `<sub_id>` and and uninstall Azure extension for SQL Server on all Arc-enabled servers where it is installed. |
| 56 | + |
| 57 | +```PowerShell |
| 58 | +.\uninstall-azure-extension-for-sql-server.ps1 -SubId <sub_id> -ResourceGroup <resource_group_name> |
| 59 | +``` |
| 60 | + |
| 61 | +# Running the script using Cloud Shell |
| 62 | + |
| 63 | +This option is recommended because Cloud shell has the Azure PowerShell modules pre-installed and you are automatically authenticated. Use the following steps to run the script in Cloud Shell. |
| 64 | + |
| 65 | +1. Launch the [Cloud Shell](https://shell.azure.com/). For details, [read more about PowerShell in Cloud Shell](https://aka.ms/pscloudshell/docs). |
| 66 | + |
| 67 | +2. Upload the script to your cloud shell using the following command: |
| 68 | + |
| 69 | + ```console |
| 70 | + curl https://raw.githubusercontent.com/microsoft/sql-server-samples/master/samples/manage/azure-arc-enabled-sql-server/uninstall-azure-extension-for-sql-server/uninstall-azure-extension-for-sql-server.ps1 -o uninstall-azure-extension-for-sql-server.ps1 |
| 71 | + ``` |
| 72 | + |
| 73 | +3. Run the script. |
| 74 | + |
| 75 | + ```console |
| 76 | + .\uninstall-azure-extension-for-sql-server.ps1 -All $True |
| 77 | + ``` |
| 78 | + |
| 79 | +> [!NOTE] |
| 80 | +> - To paste the commands into the shell, use `Ctrl-Shift-V` on Windows or `Cmd-v` on MacOS. |
| 81 | +> - The script will be uploaded directly to the home folder associated with your Cloud Shell session. |
| 82 | + |
| 83 | +# Running the script from a PC |
| 84 | + |
| 85 | + |
| 86 | +Use the following steps to run the script in a PowerShell session on your PC. |
| 87 | + |
| 88 | +1. Copy the script to your current folder: |
| 89 | + |
| 90 | + ```console |
| 91 | + curl https://raw.githubusercontent.com/microsoft/sql-server-samples/master/samples/manage/azure-arc-enabled-sql-server/uninstall-azure-extension-for-sql-server/uninstall-azure-extension-for-sql-server.ps1 -o uninstall-azure-extension-for-sql-server.ps1 |
| 92 | + ``` |
| 93 | + |
| 94 | +1. Make sure the NuGet package provider is installed: |
| 95 | + |
| 96 | + ```console |
| 97 | + Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser |
| 98 | + Install-packageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Scope CurrentUser -Force |
| 99 | + ``` |
| 100 | + |
| 101 | +1. Make sure the the Az module is installed. For more information, see [Install the Azure Az PowerShell module](https://learn.microsoft.com/powershell/azure/install-az-ps): |
| 102 | + |
| 103 | + ```console |
| 104 | + Install-Module Az -Scope CurrentUser -Repository PSGallery -Force |
| 105 | + ``` |
| 106 | + |
| 107 | +1. Connect to Azure with an authenticated account using an authentication method of your choice. For more information, see [Connect-AzAccount](https://learn.microsoft.com/powershell/module/az.accounts/connect-azaccount). |
| 108 | + |
| 109 | + ```console |
| 110 | + Connect-AzAccount <parameters> |
| 111 | + ``` |
| 112 | + |
| 113 | +1. Run the script using the desired scope. |
| 114 | + |
| 115 | + ```console |
| 116 | + .\uninstall-azure-extension-for-sql-server.ps1 -All $True |
| 117 | + ``` |
0 commit comments