The script which I have created is identifying the subscription with the quota ID and its moving all the subscriptions with the respective quota ID to the Specified Management Group.
Connect-AzAccount
$targetManagementGroupId = "Target Management Group"
$subscriptions = Get-AzSubscription
foreach ($subscription in $subscriptions) {
#Get detailed subscription information, including quota ID and current management group
$subscriptionDetails = Get-AzSubscription -SubscriptionId $subscription.Id | Select-Object -ExpandProperty ExtendedProperties
$quotaid = $subscriptionDetails.SubscriptionPolices | ConvertFrom-Json | Select-Object -ExpandProperty quotaId
#Check if the subscription is MSDN and not already in the target management group
if ($quotaId -eq "MSDN_2014-09-01" -and $subscription.ManagementGroupId -ne $targetManagementGroupId) {
try {
#Move the subscription to the target management group
New-AzManagementGroupSubscription -GroupId $targetManagementGroupId -SubscriptionId $subscription.Id
Write-Host "Subscription '$($subscription.Name)' has been moved to the management group '$targetManagementGroupId'."
} catch {
Write-Error "Error processing subscription '$($subscription.Name)': $($_.Exception.Message)"
}
} else {
Write-Host "Subscription '$($subscription.Name)' is either not an MSDN subscription or is already in the target management group."
}
}
I want the script to move only the subscriptions which are part of the Tenant Root Group which have the exact quota Id, and not move the subscriptions which are present in another management groups.

I have figured it out, i have added tags to the subscription based on the quota id, and then move it to the target management group