How do I add tags in a name=value format to Service Principals to assist with automation?

ExtraLargeFork 1 Reputation point
2025-01-10T16:33:45.6833333+00:00

I'm having trouble determining a clear answer on tagging Service Principals as the documentation seems to say you can't do it (https://zcusa.951200.xyz/en-us/azure/azure-resource-manager/management/tag-support) while several github and other resources have a command for it like so:

az ad sp update --id <service_principal_id> --add tags "<tag_key>=<tag_value>"

To confirm, I created a Service Principal in my private portal instance for test purposes. I played with it a bit and believe this code should be correct:

$sp = Get-AzADServicePrincipal -DisplayName "tempdelete"
$tags = @{"name"="value"}
Set-AzResource -ResourceId $sp.Id -Tag $tags

When I do this, I get the following error:

az account set --subscription <mysubid>
Set-AzResource: MissingSubscription : The request did not have a subscription or a valid tenant level resource provider.
CorrelationId: <some correlation id that changes every time>

The app is part of that subscription (it's my only subscription) and I'm not sure what I need to change to make this work.

PowerShell
PowerShell
A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
2,725 questions
0 comments No comments
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.