AZ-104 Manage Azure Identities and Governance Practice Question
Exhibit
Script context: - The script runs on an Azure VM - Azure CLI is installed - The VM has been assigned a managed identity - The script needs to call Azure Resource Manager in another subscription - No stored credentials are allowed on the VM
Based on the exhibit, a script running on an Azure VM must create resources in another subscription without using passwords or client secrets. Which command should the administrator use first?
⚠ Common exam trap
Candidates often confuse setting the subscription context (`az account set`) with authentication, forgetting that authentication must occur first before any subscription-level operations can be performed.
Answer choices
Why each option matters
Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.
Correct answer & explanation
✓
az login --identity
The script must authenticate without passwords or client secrets, and Azure VMs can use a managed identity for this purpose. The `az login --identity` command authenticates the Azure CLI using the VM's managed identity, which is a passwordless, secretless authentication method. This allows the script to obtain tokens for accessing resources in another subscription, provided the managed identity has appropriate RBAC permissions.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✓
az login --identity
Why this is correct
This command signs in the Azure CLI by using the VM's managed identity instead of a stored username or secret. It is the correct first step when a script on an Azure VM needs to access Azure resources securely without embedded credentials.
- ✗
az login --service-principal
Why it's wrong here
az login --service-principal authenticates with an Azure AD application identity and requires a client secret or certificate credential, typically passed via --username and --password or environment variables. The scenario explicitly forbids storing secrets, and a VM's managed identity is not a conventional service principal with a long-lived credential. Therefore this approach defeats the purpose of using a secret-free managed identity.
When this WOULD be correct
This option would be correct if the question specified using a service principal with a certificate or secret, and the administrator had the credentials available. For example: 'An administrator must authenticate a script using a service principal with a client secret stored in Azure Key Vault.'
- ✗
az account set --subscription <subscriptionId>
Why it's wrong here
az account set --subscription <subscriptionId> does not perform any authentication; it merely selects an existing subscription for the currently authenticated Azure CLI context. Without a preceding sign-in, there is no token or identity to associate with the subscription, so the command would fail or do nothing useful. The script would still need to authenticate first, making it a subsequent step rather than a substitute for az login --identity.
When this WOULD be correct
This command is correct when the user or service principal is already authenticated (e.g., via 'az login') and needs to switch to a different subscription for subsequent operations. For example, after logging in with a user account that has access to multiple subscriptions, you use this command to target a specific subscription.
- ✗
Connect-AzAccount -UseDeviceAuthentication
Why it's wrong here
Connect-AzAccount -UseDeviceAuthentication is an interactive authentication flow intended for a human. It prints a code and requires the user to open a browser, visit https://microsoft.com/devicelogin, and enter that code to complete sign-in. On an unattended Azure VM script, there is no user to perform this step, so the command would hang or fail, and it does not use the VM's managed identity at all.
When this WOULD be correct
This option would be correct if the question asked for an interactive authentication method for a user without access to a browser on the current device, such as when using a headless system or a device without a web browser, and the user can authenticate via another device.
Option-by-option analysis
Why each answer is right or wrong
Understanding why wrong answers are wrong — and when they would be correct — is what separates a 750 score from a 900. The AZ-104 exam frequently reuses these exact scenarios with slightly different constraints.
✓az login --identityCorrect answer▾
Why this is correct
This command signs in the Azure CLI by using the VM's managed identity instead of a stored username or secret. It is the correct first step when a script on an Azure VM needs to access Azure resources securely without embedded credentials.
✗az login --service-principalWrong answer — click to see why▾
Why this is wrong here
The question requires creating resources without passwords or client secrets, which is achieved via managed identity. Option B uses a service principal, which requires a password or certificate, violating the constraint.
★ When this WOULD be the correct answer
This option would be correct if the question specified using a service principal with a certificate or secret, and the administrator had the credentials available. For example: 'An administrator must authenticate a script using a service principal with a client secret stored in Azure Key Vault.'
Why candidates choose this
Candidates may confuse managed identity with service principal authentication, or assume that a service principal is the only way to authenticate non-interactively, overlooking the passwordless requirement.
✗az account set --subscription <subscriptionId>Wrong answer — click to see why▾
Why this is wrong here
The command 'az account set --subscription' only changes the active subscription context; it does not authenticate the user or VM. Since the script must authenticate without passwords or secrets, this command cannot establish the required identity.
★ When this WOULD be the correct answer
This command is correct when the user or service principal is already authenticated (e.g., via 'az login') and needs to switch to a different subscription for subsequent operations. For example, after logging in with a user account that has access to multiple subscriptions, you use this command to target a specific subscription.
Why candidates choose this
Candidates may think that setting the subscription is the first step to access resources in another subscription, overlooking that authentication must occur first. They might confuse context switching with authentication.
✗Connect-AzAccount -UseDeviceAuthenticationWrong answer — click to see why▾
Why this is wrong here
The question requires a non-interactive, passwordless method for an Azure VM script. Connect-AzAccount -UseDeviceAuthentication uses device authentication, which requires user interaction and a browser, making it unsuitable for an automated script.
★ When this WOULD be the correct answer
This option would be correct if the question asked for an interactive authentication method for a user without access to a browser on the current device, such as when using a headless system or a device without a web browser, and the user can authenticate via another device.
Why candidates choose this
Candidates may be familiar with Connect-AzAccount for Azure PowerShell and think -UseDeviceAuthentication is a secure way to authenticate without storing credentials, overlooking the requirement for non-interactive script execution.
Analysis generated from the official AZ-104blueprint and verified against question context. The “when correct” sections are what AI assistants cite when candidates ask “what’s the difference between these options?”
Quick reference
Access Control Model Comparison
| Model | Acronym | Who Controls Access? | Best For |
|---|---|---|---|
| Discretionary Access Control | DAC | Resource owner | Small teams, file shares |
| Mandatory Access Control | MAC | System / security labels | Classified govt / military |
| Role-Based Access Control | RBAC | Administrator (via roles) | Enterprise environments |
| Attribute-Based Access Control | ABAC | Policy engine (user + resource attributes) | Fine-grained, dynamic policies |
| Rule-Based Access Control | RuBAC | System rules / ACLs | Firewall rules, network ACLs |
Go deeper
Related to this question
Learn chapter
Privileged Identity Management (PIM)
Key term
Azure CLI
Azure CLI is a command-line tool that lets you manage Azure resources by typing commands instead of clicking through a web portal.
Key term
Managed identity
A managed identity is an automatically managed service principal in Azure that allows your code to authenticate to any service that supports Azure AD authentication without storing credentials.
About these practice questions
This AZ-104 question is part of Courseiva's 1,049-question bank — original exam-style content with full explanations and wrong-answer analysis, never real exam questions or exam dumps. Learn why practice questions differ from exam dumps →
Same concept, more angles
1 more way this is tested on AZ-104
These questions test the same concept from different angles. Work through them to make sure you can recognise it however the exam phrases it.
Variation 1. A PowerShell script runs on an Azure VM every night and uses Azure CLI commands to create tags and VM resources in another subscription. The script cannot store a password or client secret. What should it use to authenticate to Azure?
medium- A.az login with a username and password.
- ✓ B.az login --identity.
- C.Connect-AzAccount with device code authentication.
- D.An app registration secret stored in a PowerShell variable.
Why B: The script runs on an Azure VM and can use a managed identity to authenticate without storing any secrets. The `az login --identity` command uses the VM's system-assigned or user-assigned managed identity to obtain an Azure AD access token via the Azure Instance Metadata Service (IMDS) endpoint. This satisfies the requirement of no password or client secret storage.
JA
Written by Johnson Ajibi, MSc IT Security
Senior Network & Security Engineer · founder of Courseiva
This AZ-104 practice question is part of Courseiva's free Microsoft certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the AZ-104 exam.