Connect-AzAccount succeeds but Get-AzResource returns the wrong subscription
Documentation: Microsoft Learn
Work the problem
Authenticated to the wrong context
Fictional case: Sign-in succeeds. Get-AzContext shows the right tenant but a development subscription; the requested resource is in production.
Reasoning notebook
Record the evidence that supports your answer and the check you would run next. Your notes stay in this browser — nothing is uploaded.
Why it happens
Az PowerShell maintains a current context. A valid sign-in can restore or select a subscription that is not the target for this operation.
Check this first
What to look for
Authentication and subscription selection are separate. Confirm the subscription ID, then repeat the read query.
Working through it
- Read the current context before running a changing command.
- Select the intended subscription explicitly with Set-AzContext -SubscriptionId <id>.
- If the tenant is also wrong, reconnect or select the intended tenant before choosing the subscription.
- Run one read-only resource query and verify the subscription ID in the context.
Avoiding it next time
Verify the repair: Read Get-AzContext again and confirm the returned resource ID contains the intended subscription.
Primary documentation
Work through the incident
Verify the Azure context
A read-only inventory returned resources from the wrong subscription.
The sandbox is visible now. Sign in with Google only when you run or check a task; commands and temporary files are discarded when you leave.
Run a command to inspect its result.