Kaido Jarvemets - Logo

Tagging Azure Arc Connected Machines


Tagging your resources in Azure is an essential practice to ensure proper organization, cost management, and governance. If you have rolled out Azure Arc for server agents but forgot to tag the resources, it’s not too late to start. In this post, we’ll walk through a simple PowerShell script to tag Azure Arc-connected servers using the Az and Az.ConnectedMachine modules.

First, we need to ensure that both the Az and Az.ConnectedMachine modules are installed. The script then defines a custom function, Get-ADTieringLevel, which retrieves the tiering level of a server based on its Organizational Unit (OU) in Active Directory. Next, the script queries Azure Arc-connected servers in a specified resource group and tags each server with its tiering level using the New-AzTag cmdlet.

    This script is provided "as-is" with no warranties. Usage of this script is at
    your own risk. The author is not liable for any damages or losses arising from
    using this script. Please review the full legal disclaimer at:

Install-Module -Name Az.ConnectedMachine -Force -Verbose
Install-Module -Name Az -Force -Verbose

Function Get-ADTieringLevel


    $OU = ([adsisearcher]"(&(name=$ServerName)(objectClass=computer))").FindOne().path
    If($OU.Contains("Domain Controllers") -or $OU.Contains("Tier0")){


$ResourceGroup = "RG-PROD-IT-AZURE-ARC-WE"
$ARCConnectedMachines = Get-AzConnectedMachine -ResourceGroupName $ResourceGroup

foreach($ARCMachine in $ARCConnectedMachines){

    $ADTieringLevel = Get-ADTieringLevel -ServerName $ARCMachine.DisplayName
    $Tags = @{
        "ADTieringLevel" = $ADTieringLevel;

    New-AzTag -ResourceId $ARCMachine.Id -Tag $Tags


By using this script, you can quickly and easily tag your Azure Arc-connected servers based on their Active Directory tiering level. If you haven’t started tagging your resources, we encourage you to do so to improve resource organization and management.

Leave a Reply

Contact me

If you’re interested in learning about Tagging Azure Arc Connected Machines. I can help you understand how this solution can benefit your organization and provide a customized solution tailored to your specific needs.

Table of Contents