An implementation of the Service Locator pattern in PowerShell using Azure Tags to identify services.

Finds Azure Resources based on the tag value of “cm-service”, alongside additional filters for service type and location. Service names can be anything, and can therefore be shaped to a specific organisation’s context and uses.

The service locator pattern provides a canonical naming mechanism for Azure Resources which allows a component-based deployments, where each component is responsible for locating its own dependencies. A deployment may then fail if its dependencies are not deployed.

This command is part of the common command tooling.



Required. (String) Represents the service name to search for.


Required. (String) Represents the service key to search for. By default, this is "cm-service", but it can be overridden. Do so with caution, as this breaks a fundamental convention used in the Cloudmarque framework.


Required. (String) A location to search within - allows the same service to be deployed in multiple locations, or other commands to validate that the service is available in the specified location.


Required. (SwitchParameter) Indicates whether the resource to be located is a resource group.


Required. (SwitchParameter) Indicates that an exception should be thrown if the specified resource is unavailable. This is useful in scripts where dependencies are mandatory prior to provisioning. By default this is false, no service will be returned but a "not found" message will be written in verbose mode.


Required. (SwitchParameter) Indicates that an exception should be thrown if multiple resources are returned, by default this is false.


Example 1

Find a single keyvault
$keyVault = Get-CmAzService -Service "core-keys" -Location "USEast" -ThrowIfMultiple

Example 2

Find a single storage account for NSG logs
$storageAccount = Get-CmAzService -Service "core-monitoring-logs-nsg" -Location "USEast" -ThrowIfMultiple

Example 3

Find a set of vms
$vms = Get-CmAzService -Service "core.mySetOfVms" -Location "UKSouth"