PowerShell Genie

Connect-AzAccount succeeds but Get-AzResource returns the wrong subscription

Incident 1 min read Troubleshooting walkthrough

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.

What should you correct?

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

1PS> Get-AzContext; Get-AzSubscription | Select-Object Name,Id,TenantId,State

What to look for

Authentication and subscription selection are separate. Confirm the subscription ID, then repeat the read query.

Working through it

  1. Read the current context before running a changing command.
  2. Select the intended subscription explicitly with Set-AzContext -SubscriptionId <id>.
  3. If the tenant is also wrong, reconnect or select the intended tenant before choosing the subscription.
  4. 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

Select-Object reference

Work through the incident

Verify the Azure context

A read-only inventory returned resources from the wrong subscription.

Review the lesson

Genie guideConnect-AzAccount succeeds but Get-AzResource returns the wrong subscription

Start with the symptom, then inspect the checks and evidence. These are investigation steps; more than one cause may fit.