We are planning to have separate Management Groups for MSDN Subscription and Enterprise Subscriptions, I have able to create a Powershell script which detects the Subscription Quota ID, and move the subscription to the specific Management Group where we have applied Policies on respective Management Group for more control over the infra that is been deployed.
We want to check if there is any possibility/automation when a Enterprise/MSDN subscription is created under a Tenant Root Group, it should automatically moved to respective Management Group specified.
We have tried the Azure Policy and the Provider doesn't support the condition "Microsoft.Subscription/SubscriptionDefinitions/offerType" and in the Azure Logic App, under a when a resource event occurs there is no option to select for Subscription creation.
Any help in getting this automated will really be helpful. Providing the code for moving the Azure Subscriptions to Specified Management Group (However the script still needs to be modified as it is been moving the subscriptions which are already been part of that Management Group)
>
Connect-AzAccount
# Get the Azure subscriptions
$subscriptions = Get-AzSubscription
# Check if the subscription is an Enterprise Agreement or MSDN
foreach ($subscription in $subscriptions) {
$subscriptionName = $subscription.Name
$subscriptionDetails = Get-AzSubscription -SubscriptionId $subscription.Id | Select-Object -ExpandProperty ExtendedProperties
$quu = $subscriptionDetails.SubscriptionPolices | ConvertFrom-Json | Select-Object -ExpandProperty quotaId
if ($quu -eq "MSDN_2014-09-01") {
$subscriptionType = "MSDN"
Write-Host "Subscription '$subscriptionName' is a $subscriptionType subscription."
$ManagementGroupId = "auditonlymg"
# Move the subscription to the new management group
New-AzManagementGroupSubscription -GroupName $ManagementGroupId -SubscriptionId $subscription.Id
Write-Host "Subscription '$subscriptionName' has been moved to the management group '$ManagementGroupId'."
}
else {
Write-Host "Subscription '$subscriptionName' is not an MSDN subscription."
}
}