Azure Microsoft Technology

Validating Azure resources before moving the resources to another subscription – Part 2

In this second part, we’re going to extract Id of resource in the source subscription by using powershell.

First, we will need to connect to Azure, list all available subscription and set the context to the source subscription

# Connect to Azure Account
Connect-AzureRMAccount
 
# List subscriptions
Get-AzureRMSubscription | Select-Object Name, Subscription, Tenant | Format-List

# Select a subscription as context
Set-AzureRMContext -SubscriptionId <SourceSubscriptionId>

Next, we will get all the resource groups and resource Ids within the selected resource group.

# Get Names and Locations of resource groups 
Get-AzureRMResourceGroup | Select-Object ResourceGroupName, Location

# Extract resource Ids
$resourcesList= Get-AzureRMResource -ResourceGroupName 'DefaultResourceGroup-SEA' | Select-Object 'ResourceId'  | foreach {$_.ResourceId}
 
# Format the values by adding double quotes and join them with commas
$resourcesListFormatted= '"{0}"' -f ($resourcesList -join '","')
 
# Copy results to clipboard
Set-Clipboard -Value $resourcesListFormatted

Open up Notepad and paste in resource Ids. You will need this to construct a JSON to be used on Postman. This is based on https://docs.microsoft.com/en-us/azure/azure-resource-manager/management/move-resource-group-and-subscription#use-rest-api .

Moving on to Part 3 where we will be using Postman to obtain Auth Token and validating resources.

One thought on “Validating Azure resources before moving the resources to another subscription – Part 2

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.