Skip to content

Commit 74df34e

Browse files
committed
Make ManagementGroupId optional, default to tenant root management group
Change ManagementGroupId from required to optional in both deployment.ps1 and start-remediation.ps1. When not specified, the scripts resolve the tenant root management group ID automatically via (Get-AzContext).Tenant.Id. Changes: - deployment.ps1: ManagementGroupId parameter now Mandatory=false; auto-resolves to tenant root group with informational output - start-remediation.ps1: same parameter change and auto-resolve - README.md: updated both parameter tables (Required=No, default shown as 'Tenant root group'); simplified examples to omit ManagementGroupId where the default suffices; added explicit management group examples for users who need a custom scope
1 parent 626538f commit 74df34e

3 files changed

Lines changed: 27 additions & 11 deletions

File tree

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

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ Parameter reference:
2121

2222
| Parameter | Required | Default | Allowed values | Description |
2323
|---|---|---|---|---|
24-
| `ManagementGroupId` | Yes | N/A | Any valid management group ID | Scope where the policy definition is created. |
24+
| `ManagementGroupId` | No | Tenant root group | Any valid management group ID | Scope where the policy definition is created. Defaults to the tenant root management group when not specified. |
2525
| `ExtensionType` | No | `Both` | `Windows`, `Linux`, `Both` | Targets the Arc SQL extension platform. When `Both` (default), a single policy definition and assignment covers both platforms. When a specific type is selected, the naming and scope are tailored to that platform. |
2626
| `SubscriptionId` | No | Not set | Any valid subscription ID | If provided, policy assignment scope is the subscription. |
2727
| `TargetLicenseType` | Yes | N/A | `Paid`, `PAYG` | Target `LicenseType` value to enforce. |
@@ -56,11 +56,14 @@ Connect-AzAccount
5656
```
5757

5858
```powershell
59-
# Example: target both platforms (default)
59+
# Example: target both platforms (default), using tenant root management group
60+
.\scripts\deployment.ps1 -SubscriptionId "<subscription-id>" -TargetLicenseType "PAYG" -LicenseTypesToOverwrite @("Paid")
61+
62+
# Example: target both platforms with explicit management group
6063
.\scripts\deployment.ps1 -ManagementGroupId "<management-group-id>" -SubscriptionId "<subscription-id>" -TargetLicenseType "PAYG" -LicenseTypesToOverwrite @("Paid")
6164
6265
# Example: target only Linux
63-
.\scripts\deployment.ps1 -ManagementGroupId "<management-group-id>" -ExtensionType "Linux" -SubscriptionId "<subscription-id>" -TargetLicenseType "PAYG" -LicenseTypesToOverwrite @("Paid")
66+
.\scripts\deployment.ps1 -ExtensionType "Linux" -SubscriptionId "<subscription-id>" -TargetLicenseType "PAYG" -LicenseTypesToOverwrite @("Paid")
6467
```
6568
The first example (without `-ExtensionType`) will:
6669
* Create/update a single policy definition and assignment covering **both** Windows and Linux.
@@ -74,13 +77,13 @@ Scenario examples:
7477

7578
```powershell
7679
# Target Paid, both Linux and Windows, but only for resources with missing LicenseType or LicenseOnly (do not target PAYG)
77-
.\scripts\deployment.ps1 -ManagementGroupId "<management-group-id>" -TargetLicenseType "Paid" -LicenseTypesToOverwrite @("Unspecified","LicenseOnly")
80+
.\scripts\deployment.ps1 -TargetLicenseType "Paid" -LicenseTypesToOverwrite @("Unspecified","LicenseOnly")
7881
7982
# Target PAYG, but only where current LicenseType is Paid (do not target missing or LicenseOnly)
80-
.\scripts\deployment.ps1 -ManagementGroupId "<management-group-id>" -ExtensionType "Linux" -TargetLicenseType "PAYG" -LicenseTypesToOverwrite @("Paid")
83+
.\scripts\deployment.ps1 -ExtensionType "Linux" -TargetLicenseType "PAYG" -LicenseTypesToOverwrite @("Paid")
8184
8285
# Overwrite all known existing LicenseType values (Paid, PAYG, LicenseOnly), but not missing
83-
.\scripts\deployment.ps1 -ManagementGroupId "<management-group-id>" -ExtensionType "Linux" -TargetLicenseType "Paid" -LicenseTypesToOverwrite @("Paid","PAYG","LicenseOnly")
86+
.\scripts\deployment.ps1 -ExtensionType "Linux" -TargetLicenseType "Paid" -LicenseTypesToOverwrite @("Paid","PAYG","LicenseOnly")
8487
```
8588

8689
Note: `scripts/deployment.ps1` automatically grants required roles to the policy assignment managed identity at assignment scope, preventing common `PolicyAuthorizationFailed` errors during DeployIfNotExists deployments.
@@ -91,18 +94,21 @@ Parameter reference:
9194

9295
| Parameter | Required | Default | Allowed values | Description |
9396
|---|---|---|---|---|
94-
| `ManagementGroupId` | Yes | N/A | Any valid management group ID | Used to resolve the policy definition/assignment naming context. |
97+
| `ManagementGroupId` | No | Tenant root group | Any valid management group ID | Used to resolve the policy definition/assignment naming context. Defaults to the tenant root management group when not specified. |
9598
| `ExtensionType` | No | `Both` | `Windows`, `Linux`, `Both` | Must match the platform used for the assignment. When `Both` (default), remediates the combined assignment. |
9699
| `SubscriptionId` | No | Not set | Any valid subscription ID | If provided, remediation runs at subscription scope. |
97100
| `TargetLicenseType` | Yes | N/A | `Paid`, `PAYG` | Must match the assignment target license type. |
98101
| `GrantMissingPermissions` | No | `false` | Switch (`present`/`not present`) | If set, checks and assigns missing required roles before remediation. |
99102

100103
```powershell
101-
# Example: remediate both platforms (default)
104+
# Example: remediate both platforms (default), using tenant root management group
105+
.\scripts\start-remediation.ps1 -SubscriptionId "<subscription-id>" -TargetLicenseType "PAYG" -GrantMissingPermissions
106+
107+
# Example: remediate with explicit management group
102108
.\scripts\start-remediation.ps1 -ManagementGroupId "<management-group-id>" -SubscriptionId "<subscription-id>" -TargetLicenseType "PAYG" -GrantMissingPermissions
103109
104110
# Example: remediate only Linux
105-
.\scripts\start-remediation.ps1 -ManagementGroupId "<management-group-id>" -ExtensionType "Linux" -SubscriptionId "<subscription-id>" -TargetLicenseType "PAYG" -GrantMissingPermissions
111+
.\scripts\start-remediation.ps1 -ExtensionType "Linux" -SubscriptionId "<subscription-id>" -TargetLicenseType "PAYG" -GrantMissingPermissions
106112
```
107113

108114
## Managed Identity And Roles

samples/manage/azure-arc-enabled-sql-server/compliance/arc-sql-license-type-compliance/scripts/deployment.ps1

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
param(
2-
[Parameter(Mandatory = $true)]
2+
[Parameter(Mandatory = $false)]
33
[ValidateNotNullOrEmpty()]
44
[string]$ManagementGroupId,
55

@@ -23,6 +23,11 @@ param(
2323
[switch]$SkipManagedIdentityRoleAssignment
2424
)
2525

26+
if (-not $PSBoundParameters.ContainsKey('ManagementGroupId')) {
27+
$ManagementGroupId = (Get-AzContext).Tenant.Id
28+
Write-Output "ManagementGroupId not specified. Using tenant root management group: $ManagementGroupId"
29+
}
30+
2631
$AssignmentScope = "/providers/Microsoft.Management/managementGroups/$ManagementGroupId"
2732

2833
if ($PSBoundParameters.ContainsKey('SubscriptionId')) {

samples/manage/azure-arc-enabled-sql-server/compliance/arc-sql-license-type-compliance/scripts/start-remediation.ps1

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
param(
2-
[Parameter(Mandatory = $true)]
2+
[Parameter(Mandatory = $false)]
33
[ValidateNotNullOrEmpty()]
44
[string]$ManagementGroupId,
55

@@ -31,6 +31,11 @@ param(
3131
[switch]$GrantMissingPermissions
3232
)
3333

34+
if (-not $PSBoundParameters.ContainsKey('ManagementGroupId')) {
35+
$ManagementGroupId = (Get-AzContext).Tenant.Id
36+
Write-Output "ManagementGroupId not specified. Using tenant root management group: $ManagementGroupId"
37+
}
38+
3439
$AssignmentScope = "/providers/Microsoft.Management/managementGroups/$ManagementGroupId"
3540

3641
if ($PSBoundParameters.ContainsKey('SubscriptionId')) {

0 commit comments

Comments
 (0)