az cli subscription change

Az CLI: Managing & Changing Azure Subscriptions

By Christopher Lewis
AD

Managing Azure subscriptions has never been more straightforward thanks to the Azure CLI (Command Line Interface), a powerful tool that allows you to execute commands to manage Azure resources. One of the key operations you'll need to perform is changing the subscription for your Azure resources. Let's delve into the process and explore how to efficiently manage your Azure subscriptions using the Azure CLI.

Azure CLI provides a user-friendly way to interact with your Azure resources, enabling you to change subscriptions with just a few commands. Before we dive into the process, ensure that you have installed the latest version of the Azure CLI and logged in using `az login`.

Switching Azure Subscriptions

The first step in changing your Azure subscription using the Azure CLI is to switch to the desired subscription. Azure CLI provides a simple command to accomplish this task.

AD
How To Upgrade Or Change Your Member Subscription
How To Upgrade Or Change Your Member Subscription
a cell phone with the subs section highlighted in black and white text on it
a cell phone with the subs section highlighted in black and white text on it
an iphone screen with the text how do i cancel my subscription?
an iphone screen with the text how do i cancel my subscription?

Let's begin by listing all available subscriptions. Use the following command to display a list of your subscriptions:

az account list --output table

You'll see a table listing your subscriptions with their IDs and names. To switch to a specific subscription, use the following command, replacing <subscriptionId> with the ID of your target subscription:

an email message with the caption'your subription has been successfully corrected '
an email message with the caption'your subription has been successfully corrected '
the app is showing how to use subscription for an email message or email address
the app is showing how to use subscription for an email message or email address
The subscription economy is changing fast — and so is how people respond to it. The trend worth watc
The subscription economy is changing fast — and so is how people respond to it. The trend worth watc
az account set --subscription <subscriptionId>

Once you've changed your active directory and subscription, the next step involves changing the subscription of specific Azure resources.

Changing Subscription for Azure Resources

To change the subscription for your Azure resources, you'll first need to determine which resources are present in your current subscription. You can achieve this using the `az group list` command, which displays all resource groups in your current subscription.

AD

To change the subscription for a specific resource, follow these steps. First, identify the resource ID, which uniquely identifies the resource within Azure. You can find the resource ID in the Azure portal. Once you have the resource ID, use the following command to update the resource group and subscription:

How to manage your subscriptions
How to manage your subscriptions
Cancel or Keep? How to Cut Subscription Costs Without Losing What You Love | AAA Club Alliance
Cancel or Keep? How to Cut Subscription Costs Without Losing What You Love | AAA Club Alliance
an email form with the text subcription expired on it, in red and blue
an email form with the text subcription expired on it, in red and blue
a screenshot of a cell phone with the text charged for a called subcription
a screenshot of a cell phone with the text charged for a called subcription
Subscription Cancellation Challenge (Save Hundreds)
Subscription Cancellation Challenge (Save Hundreds)
Subscription & Account
Subscription & Account
az resource move --id /subscriptions/<source-subscription-id>/resourceGroups/<resource-group-name> --destination /subscriptions/<destination-subscription-id>

Replace <source-subscription-id> with the ID of the subscription you're moving the resource from, <resource-group-name> with the name of the resource group containing the resource, and <destination-subscription-id> with the ID of the target subscription.

Changing Subscription for Multiple Resources

To streamline the process when moving multiple resources, you can use PowerShell or scripting languages like Bash to automate the process. By looping through a list of resource IDs and executing the `az resource move` command, you can efficiently change the subscription for numerous resources at once.

AD

Here's an example of how you can use Bash scripting to move multiple resources to a new subscription:

a text message that reads, dear subber your one month subscription has been recharged successfully
a text message that reads, dear subber your one month subscription has been recharged successfully
How To Cancel Starz Subscription? Guide To Avoid Fees [2025]
How To Cancel Starz Subscription? Guide To Avoid Fees [2025]
Subscriptions Americans Forget to Cancel
Subscriptions Americans Forget to Cancel
Types of subscription services - infographic
Types of subscription services - infographic
Use subscription templates
Use subscription templates
Update or change credit card information
Update or change credit card information
How to find and cancel your unused subscriptions - Engadget
How to find and cancel your unused subscriptions - Engadget
Digital Subscription Hub
Digital Subscription Hub
the app is showing how to get free with special offers on your phone or tablet
the app is showing how to get free with special offers on your phone or tablet
an image of a website page with different colors and font
an image of a website page with different colors and font
a red and white email form with the words, your subcription is due
a red and white email form with the words, your subcription is due
5 Apps to Cancel Your Subscriptions
5 Apps to Cancel Your Subscriptions
the info sheet shows how to use subscription and win - back flow
the info sheet shows how to use subscription and win - back flow
  • Create a file named `move-resources.sh` with the following content:
#!/bin/bash

subscription_id="<destination-subscription-id>"
resource_group_name="<resource-group-name>"

for id in "${resource_ids[@]}"
do
  az resource move --id $id --destination "/subscriptions/$subscription_id"
done
  • Update the `subscription_id` and `resource_group_name` variables as needed.
  • Replace `resource_ids` with an array containing the resource IDs you want to move.
  • Run the script using the command `bash move-resources.sh`.

Managing Subscription Access

Sometimes, you may need to grant or revoke access to specific Azure subscriptions for users or service principals. Azure CLI provides commands to manage role assignments, allowing you to control access to your subscriptions efficiently.

First, let's list all available roles and their IDs using the following command:

AD
az role definition list --output table

Now, you can use the `az role assignment create` command to grant a role to a user, group, or service principal. Here's an example of assigning the "Owner" role to a user:

az role assignment create --assignee <user-email> --role <role-name> --scope /subscriptions/<subscriptionId>

To remove access, you can use the `az role assignment delete` command. Replace <assignment-id> with the ID of the role assignment you want to delete:

az role assignment delete --assignment <assignment-id>

Managing Subscription-Level Access

When managing access at the subscription level, use the subscription ID as the scope. For example, to assign the "Contributor" role to a service principal, use the following command:

az role assignment create --assignee <principal-id> --role <role-name> --scope /subscriptions/<subscriptionId>

Control over Azure subscriptions is crucial for managing access and resources effectively. By leveraging the Azure CLI, you can streamline your subscription management processes, increasing efficiency and saving time.

As you've seen, changing your Azure subscription and managing access using the Azure CLI is a straightforward process. Whether you need to switch subscriptions, move resources, or manage access, the Azure CLI provides the tools you need to accomplish these tasks efficiently. Embrace the power of the Azure CLI today and take control of your Azure environment.

AD