Why Automate Azure Arc Onboarding?
Manually onboarding servers to Azure Arc is straightforward for a handful of machines — but at scale (hundreds or thousands of servers), it quickly becomes unmanageable. In this post, I walk through the approach I use to bulk-onboard servers with PowerShell and Azure Automation.
The Architecture
The solution consists of three main pieces:
- A Service Principal with
Azure Connected Machine Onboardingrights scoped to the target subscription. - A PowerShell runbook in Azure Automation that generates a scoped onboarding script for each server batch.
- A scheduled pipeline (via GitHub Actions or Azure Automation schedules) that drives the process.
Sample Onboarding Script
# Generate an Azure Arc onboarding script
$params = @{
SubscriptionId = "<subscription-id>"
ResourceGroupName = "Arc-Servers-RG"
Location = "westeurope"
TenantId = "<tenant-id>"
ServicePrincipalId = $env:ARC_SP_ID
ServicePrincipalSecret = $env:ARC_SP_SECRET
}
Invoke-WebRequest -Uri "https://aka.ms/azcmagent-windows" -OutFile "$env:TEMP\install_windows_azcmagent.ps1"
& "$env:TEMP\install_windows_azcmagent.ps1"
azcmagent connect @params
Tips for Production Deployments
- Proxy environments: Use
azcmagent config set proxy.url http://proxy:8080before connecting. - Tagging: Pass
--tagstoazcmagent connectto apply environment, owner, and cost-centre tags at onboarding time. - Error handling: Wrap each connect call in
try/catchand log failures to an Azure Storage table for easy tracking.
Next Steps
Once onboarded, you can apply Azure Policy, enable Defender for Servers, and manage patching via Azure Update Manager — all from a single pane of glass in the Azure portal.