Write-Host "Logging in to Azure..."
az login --only-show-errors | Out-Null
$subscriptionId = Read-Host "Enter the Subscription ID or Subscription Name"
Write-Host "Setting subscription: $subscriptionId ..."
az account set --subscription $subscriptionId
$currentSubscription = az account show --query "id" -o tsv
Write-Host "Using subscription: $currentSubscription"
Write-Host ""
$providers = @(
"Microsoft.Resources",
"Microsoft.CognitiveServices",
"Microsoft.DBforPostgreSQL",
"Microsoft.Search",
"Microsoft.Storage",
"Microsoft.ServiceBus",
"Microsoft.Insights",
"Microsoft.Web",
"Microsoft.Logic",
"Microsoft.Communication",
"Microsoft.Solutions",
"Microsoft.BackupSolutions",
"Microsoft.ApiCenter",
"Microsoft.ApiManagement",
"Microsoft.HealthcareApis",
"Microsoft.DocumentDB",
"Microsoft.DBforMySQL",
"Microsoft.App",
"Microsoft.Cdn",
"Microsoft.Compute",
"Microsoft.BotService",
"Microsoft.AlertsManagement",
"Microsoft.AppConfiguration",
"Microsoft.Cache",
"Microsoft.ContainerService",
"Microsoft.OperationalInsights",
"Microsoft.Network"
)
$total = $providers.Count
$completed = 0
$failed = @()
Write-Host "Starting registration of $total providers..."
Write-Host ""
foreach ($provider in $providers) {
$completed++
$remaining = $total - $completed
Write-Host "[$completed/$total] Registering $provider (Remaining: $remaining)"
try {
$state = az provider show --namespace $provider --query "registrationState" -o tsv 2>$null
if ($state -eq "Registered") {
Write-Host " Already registered"
continue
}
az provider register --namespace $provider --wait --only-show-errors 2>$null
$final = az provider show --namespace $provider --query "registrationState" -o tsv
if ($final -ne "Registered") {
Write-Host " Failed to register $provider"
$failed += $provider
} else {
Write-Host " Successfully registered"
}
}
catch {
Write-Host " Error occurred for $provider"
$failed += $provider
}
Write-Host ""
}
Write-Host "----------------------------------------------"
Write-Host "Registration Completed"
Write-Host "Total Providers: $total"
Write-Host "Successfully Completed: $($total - $failed.Count)"
Write-Host "Failed: $($failed.Count)"
Write-Host "----------------------------------------------"
if ($failed.Count -gt 0) {
Write-Host "Failed Providers:"
$failed | ForEach-Object { Write-Host " - $_" }
} else {
Write-Host "All providers registered successfully."
}