Find Azure Arc Resources based on Tags in PowerShell

Get-AzConnectedMachine

The Get-AzConnectedMachine cmdlet can be used to retrieve information about the hybrid machine and pipe them to the Where-Objet to filter by the tag name and tag value.

Get-AzConnectedMachine | Where-Object {( $_.Tag.Keys -eq $TagKey) -and ($_.Tag.Values -eq $TagValue)} | ft Name, Tag

Get-AzResource cmdlet

The Get-AzResource cmdlet can be used for any type of Azure resource and we will filter for Azure Arc using the -ResourceType parameter with Microsoft.HybridCompute/machines value

Get-AzResource -ResourceType Microsoft.HybridCompute/machines

As described in Get Azure Resources based on Tags in PowerShell we can extend this sample with parameters for the tag name and tag value.

Get-AzResource -ResourceType Microsoft.HybridCompute/machines -TagName $TagName -TagValue $TagValue
PowerShell
Azure Arc

Comments