From 7a33c7e140753e2495549e18e902eeca805e8234 Mon Sep 17 00:00:00 2001 From: "Alexander (Sasha) Nosov" Date: Thu, 16 Feb 2023 10:08:14 -0800 Subject: [PATCH 1/2] removed update folder --- .../azure-arc-enabled-sql-server/update-license-type/README.md | 0 .../update-license-type/update-licence-type.ps1 | 0 2 files changed, 0 insertions(+), 0 deletions(-) delete mode 100644 samples/manage/azure-arc-enabled-sql-server/update-license-type/README.md delete mode 100644 samples/manage/azure-arc-enabled-sql-server/update-license-type/update-licence-type.ps1 diff --git a/samples/manage/azure-arc-enabled-sql-server/update-license-type/README.md b/samples/manage/azure-arc-enabled-sql-server/update-license-type/README.md deleted file mode 100644 index e69de29b..00000000 diff --git a/samples/manage/azure-arc-enabled-sql-server/update-license-type/update-licence-type.ps1 b/samples/manage/azure-arc-enabled-sql-server/update-license-type/update-licence-type.ps1 deleted file mode 100644 index e69de29b..00000000 From 8dce6fe4d747537ae4fabdcf30167bbd83de186d Mon Sep 17 00:00:00 2001 From: "Alexander (Sasha) Nosov" Date: Thu, 16 Feb 2023 10:15:42 -0800 Subject: [PATCH 2/2] Added extension version requirement --- .../modify-license-type/README.md | 51 +++++++++++++++---- .../modify-license-type.ps1 | 7 +-- 2 files changed, 44 insertions(+), 14 deletions(-) diff --git a/samples/manage/azure-arc-enabled-sql-server/modify-license-type/README.md b/samples/manage/azure-arc-enabled-sql-server/modify-license-type/README.md index 31673f1a..1fc47839 100644 --- a/samples/manage/azure-arc-enabled-sql-server/modify-license-type/README.md +++ b/samples/manage/azure-arc-enabled-sql-server/modify-license-type/README.md @@ -3,13 +3,12 @@ services: Azure Arc-enabled SQL Server platforms: Azure author: anosov1960 ms.author: sashan -ms.date: 2/09/2023 +ms.date: 2/16/2023 --- # Overview - This script allows you to to set or change the license type on all Azure-connected SQL Servers on a specific resource, in a single resource group, a specific subscription, a list of subscriptions or all subscriptions to which you have access. By default, it sets the specified license type value on the servers where it is undefined. But you can request to set it on all servers in the selected scope. @@ -18,10 +17,10 @@ If not specified, all subscriptions your role has access to are scanned. If the license type is not specified, the value "Paid" is used. +# Prerequisites -# Required permissions - -You must have at least a *Contributor* role in each subscription you modify. +- 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. # Launching the script @@ -32,7 +31,7 @@ The script accepts the following command line parameters: |-SubId|subscription_id *or* a file_name|Optional: subscription id or a .csv file with the list of subscriptions1. If not specified all subscriptions will be scanned| |-ResourceGroup |resource_group_name|Optional: Limit the scope to a specific resource group| |-MachineName |machine_name|Optional: Limit the scope to a specific machine| -|-LicenceType | "Paid" (default), "PAYG" or "LicenseOnly"| Specifies the license type value | +|-LicenceType | "Paid", "PAYG" or "LicenseOnly"| Required: Specifies the license type value | |-All|\$True or \$False (default)|Optional. Set the new license type for all installed extensions. By default the value is set only if license type is undefined.| 1You can create a .csv file using the following command and then edit to remove the subscriptions you don't want to scan. @@ -45,7 +44,7 @@ Get-AzSubscription | Export-Csv .\mysubscriptions.csv -NoTypeInformation The following command will scan all the subscriptions to which the user has access to, and set the license type to "Paid" on all servers where license type is undefined. ```PowerShell -.\update-license-type.ps1 -LicenseType Paid +.\modify-license-type.ps1 -LicenseType Paid ``` ## Example 2 @@ -53,7 +52,7 @@ The following command will scan all the subscriptions to which the user has acce The following command will scan the subscription `` and set the license type value to "Paid" on all servers. ```PowerShell -.\update-license-type.ps1 -SubId -LicenseType Paid -All $True +.\modify-license-type.ps1 -SubId -LicenseType Paid -All $True ``` ## Example 3 @@ -61,16 +60,16 @@ The following command will scan the subscription `` and set the license The following command will scan resource group in the subscription `` and set the license type value to "PAYG" on all servers. ```PowerShell -.\update-license-type.ps1 -SubId -ResourceGroup -LicenseType PAYG -All $True +.\modify-license-type.ps1 -SubId -ResourceGroup -LicenseType PAYG -All $True ``` # Running the script using Cloud Shell -Use the following steps to run the script in 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. 1. Launch the [Cloud Shell](https://shell.azure.com/). For details, [read more about PowerShell in Cloud Shell](https://aka.ms/pscloudshell/docs). -2. Upload the script to the shell using the following command: +2. Upload the script to your cloud shell using the following command: ```console curl https://raw.githubusercontent.com/microsoft/sql-server-samples/master/samples/manage/azure-arc-enabled-sql-server/modify-license-type/modify-license-type.ps1 -o modify-license-type.ps1 @@ -86,3 +85,33 @@ Use the following steps to run the script in Cloud Shell. > - To paste the commands into the shell, use `Ctrl-Shift-V` on Windows or `Cmd-v` on 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. + +1. Copy the script to your current folder: + + ```console + curl https://raw.githubusercontent.com/microsoft/sql-server-samples/master/samples/manage/azure-arc-enabled-sql-server/modify-license-type/modify-license-type.ps1 -o modify-license-type.ps1 + ``` + +1. Use the following commands to install the Az module. For more information, see [Install the Azure Az PowerShell module](https://learn.microsoft.com/powershell/azure/install-az-ps): + + ```console + Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser + Install-packageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force + Install-Module Az -Scope CurrentUser -Repository PSGallery -Force + ``` + +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). + + ```console + Connect-AzAccount + ``` + +1. Run the script using the desired scope. + + ```console + .//modify-license-type.ps1 -LicenseType Paid + ``` diff --git a/samples/manage/azure-arc-enabled-sql-server/modify-license-type/modify-license-type.ps1 b/samples/manage/azure-arc-enabled-sql-server/modify-license-type/modify-license-type.ps1 index 194935d1..3b32e70a 100644 --- a/samples/manage/azure-arc-enabled-sql-server/modify-license-type/modify-license-type.ps1 +++ b/samples/manage/azure-arc-enabled-sql-server/modify-license-type/modify-license-type.ps1 @@ -13,7 +13,7 @@ # -ResourceGroup [resource_goup] (Limit scope to a specific resoure group) # -MachineName [machine_name] (Limit scope to a specific machine) # -LicenseType [license_type_value] (Specific LT value) -# -All (Optional. Set the new license type on all installed extensions. +# -All (Required. Set the new license type on all installed extensions. # By default the value is set only if license type is undefined undefined) # # The script uses a function ConvertTo-HashTable that was created by Adam Bertram (@adam-bertram). @@ -28,8 +28,9 @@ param ( [string] $ResourceGroup, [Parameter (Mandatory= $false)] [string] $MachineName, - [Parameter (Mandatory= $false)] - [string] $LicenseType="Paid", + [Parameter (Mandatory= $true)] + [ValidateSet(“PAYG”,”Paid”,"LicenseOnly”)] + [string] $LicenseType, [Parameter (Mandatory= $false)] [boolean] $All=$false )