Skip to content

Commit 8dce6fe

Browse files
author
Alexander (Sasha) Nosov
committed
Added extension version requirement
1 parent 7a33c7e commit 8dce6fe

File tree

2 files changed

+44
-14
lines changed

2 files changed

+44
-14
lines changed

samples/manage/azure-arc-enabled-sql-server/modify-license-type/README.md

Lines changed: 40 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,12 @@ services: Azure Arc-enabled SQL Server
33
platforms: Azure
44
author: anosov1960
55
ms.author: sashan
6-
ms.date: 2/09/2023
6+
ms.date: 2/16/2023
77
---
88

99

1010
# Overview
1111

12-
1312
This script allows you to to set or change the license type on all Azure-connected SQL Servers
1413
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.
1514

@@ -18,10 +17,10 @@ If not specified, all subscriptions your role has access to are scanned.
1817

1918
If the license type is not specified, the value "Paid" is used.
2019

20+
# Prerequisites
2121

22-
# Required permissions
23-
24-
You must have at least a *Contributor* role in each subscription you modify.
22+
- You must have at least a *Contributor* role in each subscription you modify.
23+
- The Azure extension for SQL Server is updated to version 1.1.2230.58 or newer.
2524

2625
# Launching the script
2726

@@ -32,7 +31,7 @@ The script accepts the following command line parameters:
3231
|-SubId|subscription_id *or* a file_name|Optional: subscription id or a .csv file with the list of subscriptions<sup>1</sup>. If not specified all subscriptions will be scanned|
3332
|-ResourceGroup |resource_group_name|Optional: Limit the scope to a specific resource group|
3433
|-MachineName |machine_name|Optional: Limit the scope to a specific machine|
35-
|-LicenceType | "Paid" (default), "PAYG" or "LicenseOnly"| Specifies the license type value |
34+
|-LicenceType | "Paid", "PAYG" or "LicenseOnly"| Required: Specifies the license type value |
3635
|-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.|
3736

3837
<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.
@@ -45,32 +44,32 @@ Get-AzSubscription | Export-Csv .\mysubscriptions.csv -NoTypeInformation
4544
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.
4645

4746
```PowerShell
48-
.\update-license-type.ps1 -LicenseType Paid
47+
.\modify-license-type.ps1 -LicenseType Paid
4948
```
5049

5150
## Example 2
5251

5352
The following command will scan the subscription `<sub_id>` and set the license type value to "Paid" on all servers.
5453

5554
```PowerShell
56-
.\update-license-type.ps1 -SubId <sub_id> -LicenseType Paid -All $True
55+
.\modify-license-type.ps1 -SubId <sub_id> -LicenseType Paid -All $True
5756
```
5857

5958
## Example 3
6059

6160
The following command will scan resource group <resource_group_name> in the subscription `<sub_id>` and set the license type value to "PAYG" on all servers.
6261

6362
```PowerShell
64-
.\update-license-type.ps1 -SubId <sub_id> -ResourceGroup <resource_group_name> -LicenseType PAYG -All $True
63+
.\modify-license-type.ps1 -SubId <sub_id> -ResourceGroup <resource_group_name> -LicenseType PAYG -All $True
6564
```
6665

6766
# Running the script using Cloud Shell
6867

69-
Use the following steps to run the script in Cloud Shell.
68+
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.
7069

7170
1. Launch the [Cloud Shell](https://shell.azure.com/). For details, [read more about PowerShell in Cloud Shell](https://aka.ms/pscloudshell/docs).
7271

73-
2. Upload the script to the shell using the following command:
72+
2. Upload the script to your cloud shell using the following command:
7473

7574
```console
7675
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.
8685
> - To paste the commands into the shell, use `Ctrl-Shift-V` on Windows or `Cmd-v` on MacOS.
8786
> - The script will be uploaded directly to the home folder associated with your Cloud Shell session.
8887

88+
# Running the script from a PC
89+
90+
91+
Use the following steps to run the script in a PowerShell session on your PC.
92+
93+
1. Copy the script to your current folder:
94+
95+
```console
96+
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
97+
```
98+
99+
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):
100+
101+
```console
102+
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
103+
Install-packageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force
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+
.//modify-license-type.ps1 -LicenseType Paid
117+
```

samples/manage/azure-arc-enabled-sql-server/modify-license-type/modify-license-type.ps1

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
# -ResourceGroup [resource_goup] (Limit scope to a specific resoure group)
1414
# -MachineName [machine_name] (Limit scope to a specific machine)
1515
# -LicenseType [license_type_value] (Specific LT value)
16-
# -All (Optional. Set the new license type on all installed extensions.
16+
# -All (Required. Set the new license type on all installed extensions.
1717
# By default the value is set only if license type is undefined undefined)
1818
#
1919
# The script uses a function ConvertTo-HashTable that was created by Adam Bertram (@adam-bertram).
@@ -28,8 +28,9 @@ param (
2828
[string] $ResourceGroup,
2929
[Parameter (Mandatory= $false)]
3030
[string] $MachineName,
31-
[Parameter (Mandatory= $false)]
32-
[string] $LicenseType="Paid",
31+
[Parameter (Mandatory= $true)]
32+
[ValidateSet(PAYG,Paid,"LicenseOnly)]
33+
[string] $LicenseType,
3334
[Parameter (Mandatory= $false)]
3435
[boolean] $All=$false
3536
)

0 commit comments

Comments
 (0)