Offboard Azure management group or tenant scope (ARM) ↗
Follow this procedure to offboard a Microsoft Azure Management Group or Tenant scope from Cortex XSIAM and cleanly decommission all deployed resources.
Important
This offboarding script is designed for environments onboarded with BASE template version 1.4.18 or later. If your onboarding was deployed with an older BASE template version, this script may not fully remove all provisioned resources and could leave orphaned artifacts. Please verify your onboarding template version before proceeding.
Prerequisites
Before you begin, ensure you meet the following requirements:
Tooling requirements
- Bash (version \(\ge\) 4.0)
- Azure CLI (version \(\ge\) 2.61)
- jq (JSON processor)
Working directory
You must run the offboarding script from the same directory where the files parameters.sh and graphAPIRoles.json are located. These files are packaged with the onboarding template:
parameters.sh: Contains configuration parameters (such asresource_suffix,tenant_id, andcustomer_object_id) which the script auto-loads at startup.graphAPIRoles.json: Defines the Microsoft Graph app role assignments to remove.
Required Azure permissions
The authenticated session must be run by a user or service principal with the following roles:
- Global Administrator: Required for managing Entra ID diagnostic settings and service principal operations.
- Owner: Required at the management group scope for deleting deployment stacks, policy resources, role assignments, role definitions, and resource groups.
Authentication
Run the following command in your terminal to authenticate with the correct Azure tenant:
az login --tenant <tenant-id>
How to offboard Microsoft Azure MG or tenant scope - ARM method
Gather required values
Before running the offboarding script, collect the following values:
| Variable | Description | Where to find it |
|---|---|---|
<mg-id> | The management group ID being offboarded. | Azure portal > Management groups, or run az account management-group list -o table. |
<tenant-root-mg-id> | The tenant-root management group ID (for tenant scope only). Typically matches your Azure tenant ID. | Azure portal > Management groups > the top-level group, or run az account management-group list -o table. |
<sub-id> | The subscription ID hosting the Cortex onboarding resource group (cortex-onboarding-<resource_suffix>). | Azure portal > Subscriptions, or run az account list -o table. |
Locate your offboarding bundle
Navigate to the directory containing these files before proceeding. The bundle contains the following files, which must all be present in the same directory:
| File | Description |
|---|---|
parameters.sh | Connector-specific parameters, including resource_suffix, tenant_id, and customer_object_id. Auto-loaded by the script at startup. |
graphAPIRoles.json | Defines which Microsoft Graph app role assignments to remove. |
offboard_mg_tenant.sh | Interactive offboarding script. |
Understand the offboarding phases
The script executes the following phases in a fixed order. In dry-run mode, each phase lists the resources it would delete without making any changes. In action mode, each phase deletes the identified resources and the final phase verifies that all resources have been removed.
| Script phase | What it does |
|---|---|
diagnostics | Deletes the management group diagnostic setting. For tenant scope, also deletes the Entra ID diagnostic setting. |
stack | Deletes the deployment stack cortex-policy-<resource_suffix> at management group scope. |
onboarding-rg | Deletes the onboarding resource group cortex-onboarding-<resource_suffix>, which cascades deletion of the managed identity. |
graph-api-roles | Removes Microsoft Graph app role assignments from the customer service principal. |
policy | Deletes per-subscription policy-deployed resources across all child subscriptions: role assignments, role definitions, and the policy resource group. |
verify | Confirms all targeted resources are gone. Skipped in dry-run mode. |
Run the offboard_mg_tenant.sh script in dry-run mode
First, run the script in dry-run mode (the default) to preview all resources that would be deleted and verify your permissions are correct. No changes are made during a dry run.
For management group scope, run:
bash offboard_mg_tenant.sh \ --scope management_group \ --management-group-id <mg-id> \ --subscription-id <sub-id>
For tenant scope run:
bash offboard_mg_tenant.sh \ --scope tenant \ --management-group-id <tenant-root-mg-id> \ --subscription-id <sub-id>
Review the dry-run output carefully and confirm that the listed resources are correct before proceeding.
Run the offboarding cleanup
After reviewing the dry-run output, run the script with --no-dry-run to delete the resources.
For a management group scope connector:
bash offboard_mg_tenant.sh \ --scope management_group \ --management-group-id <mg-id> \ --subscription-id <sub-id> \ --no-dry-run
For a tenant scope connector:
bash offboard_mg_tenant.sh \ --scope tenant \ --management-group-id <tenant-root-mg-id> \ --subscription-id <sub-id> \ --no-dry-run
Verification and troubleshooting
Review the script output and confirm that all targeted resources were removed:
- Success: You will see a final confirmation message in your terminal indicating that cleanup is complete (Exit Code
0). - Leftover Resources: If the script times out or detects that any policy-deployed resources still remain, it will log the specific failed resources in the console output and exit with code
30. This is usually due to transient Azure API replication delays. You can safely re-run the cleanup script with the--no-dry-runflag to trigger another verification and cleanup sweep. See #reference-script-exit-codes for the exit code details.
Troubleshooting
The deployment stack was already deleted
If the deployment stack was deleted manually or in a prior partial run, the script cannot auto-resolve the extResourceSuffix and exits with code 10. The value of <ext-value> is printed in the logs when you run the offboard script. Pass the --ext-resource-suffix flag with that value to resume:
bash offboard_mg_tenant.sh \ --scope <tenant|management_group> \ --management-group-id <mg-id> \ --subscription-id <sub-id> \ --ext-resource-suffix <ext-value> \ --no-dry-run
Verification fails after the action
The script automatically re-runs the cleanup and re-verifies up to three times. Transient Azure API delays are the most common cause. If issues persist after three attempts, inspect the remaining resources using the IDs shown in the verification output and re-run the script with --no-dry-run to trigger another cleanup sweep.
Reference: Script exit codes
Use the following exit codes to understand the script results:
| Code | Meaning |
|---|---|
0 | Success, dry-run completed, or nothing to delete |
10 | Preflight failure (missing flag, authentication error, or extResourceSuffix unresolvable. Pass --ext-resource-suffix) |
21–25 | Single phase failure (diagnostics / stack / onboarding-rg / graph-api-roles / policy) |
30 | Verification found leftover resources |
40 | Two or more phases failed |
130 | Interrupted (SIGINT) |