services, platforms, author, ms.author, ms.date
| services | platforms | author | ms.author | ms.date |
|---|---|---|---|---|
| Azure Arc-enabled SQL Server | Azure | anosov1960 | sashan | 4/6/2023 |
Overview
This script provides a scalable solution to uninstall Azure extension for SQL Server on a specific Arc-enabled server,
all Arc-enabled servers in a specific resource group, specific subscription, a list of subscriptions or the entire account.
You can specify a single subscription to scan, or provide a list of subscriptions as a .CSV file.
Prerequisites
- You must have at least a Contributor role in each subscription you modify.
- The Azure extension for SQL Server is updated to version 1.1.2230.58 or newer.
- You must be connected to Azure AD and logged in to your Azure account. If your account have access to multiple tenants, make sure to log in with a specific tenant ID.
Launching the script
The script accepts the following command line parameters:
| Parameter | Value | Description |
|---|---|---|
| -SubId | subscription_id or a file_name or ALL | Required: modify a specific subscription id, a list of subscriptions in a .csv file1, or ALL subscriptions |
| -ResourceGroup | resource_group_name | Optional: Limit the scope to a specific resource group |
| -MachineName | machine_name | Optional: Limit the scope to a specific machine |
1You can create a .csv file using the following command and then edit to remove the subscriptions you don't want to scan.
Get-AzSubscription | Export-Csv .\mysubscriptions.csv -NoTypeInformation
Example 1
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.
.\uninstall-azure-extension-for-sql-server.ps1 -SubId ALL
Example 2
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.
.\uninstall-azure-extension-for-sql-server.ps1 -SubId <sub_id>
Example 3
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.
.\uninstall-azure-extension-for-sql-server.ps1 -SubId <sub_id> -ResourceGroup <resource_group_name>
Example 4
The following command will uninstall Azure extension for SQL Server on a specific Arc-enabled server.
.\uninstall-azure-extension-for-sql-server.ps1 -SubId <sub_id> -MachineName <machine_name>
Running the script using Cloud Shell
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.
-
Launch the Cloud Shell. For details, read more about PowerShell in Cloud Shell.
-
Connect to Azure AD
Connect-AzureAD -
Upload the script to your cloud shell using the following command:
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 -
Run the script using the desired scope. For example:
.\uninstall-azure-extension-for-sql-server.ps1 -SubId <sub_id>
Note
- To paste the commands into the shell, use
Ctrl-Shift-Von Windows orCmd-von MacOS.- The script will be uploaded directly to the home folder associated with your Cloud Shell session.
Running the script from a PC
Use the following steps to run the script in a PowerShell session on your PC.
-
Copy the script to your current folder:
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 -
Make sure the NuGet package provider is installed:
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser Install-packageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Scope CurrentUser -Force -
Make sure the the Az module is installed. For more information, see Install the Azure Az PowerShell module:
Install-Module Az -Scope CurrentUser -Repository PSGallery -Force -
Connect to Azure AD and login to your Azure account.
Connect-AzureAD Connect-AzAccount -TenantID (Get-AzureADTenantDetail).ObjectId -
Run the script using the desired scope. For example:
.\uninstall-azure-extension-for-sql-server.ps1 -SubId <sub_id> -ResourceGroup <resource_group>