Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get-AzResourceGroup on -Id requires Set-AzContext to given sub first, unlike how Get-AzResource works #21725

Closed
o-l-a-v opened this issue May 8, 2023 · 1 comment · Fixed by #21765
Assignees
Labels
Azure PS Team bug This issue requires a change to an existing behavior in the product in order to be resolved. customer-reported Investigate 🔍

Comments

@o-l-a-v
Copy link

o-l-a-v commented May 8, 2023

Description

Get-AzResourceGroup -Id <resourcegroupid> fail with "Provided resource group does not exist", until you Set-AzContext to the subscription the resource group in question is located.

This is inconsistent with how Get-AzResource -ResourceId works. If -ResourceId is given, the rest call uses it vs. current Az scope.

Issue script & Debug output

# Assets
$Sub1Guid = 'some_guid'
$Sub2Guid = 'some_other_guid'
$RgName   = 'some_rg_name'

# Generate resource id of the resource group in question
$ResourceGroupId = '/subscriptions/{0}/resourceGroups/{1}' -f $Sub2Guid, $RgName

# Set context to sub1
Set-AzContext -Subscription $Sub1Guid

# Try to get rg on resource id => Fails
Get-AzResourceGroup -Id $ResourceGroupId

# Set context to sub2
Set-AzContext -Subscription $Sub2Guid

# Try to get rg on resource id => Succeeds
Get-AzResourceGroup -Id $ResourceGroupId

Environment data

Windows PowerShell 5.1

Module versions

Az.Resources 6.6.1

Error output

No response

@o-l-a-v o-l-a-v added bug This issue requires a change to an existing behavior in the product in order to be resolved. needs-triage This is a new issue that needs to be triaged to the appropriate team. labels May 8, 2023
@ghost ghost added customer-reported and removed needs-triage This is a new issue that needs to be triaged to the appropriate team. labels May 8, 2023
@isra-fel
Copy link
Member

We are investigating the root cause. At first glance it looks like a bug of Get-AzResourceGroup to only take resource group name from the id.

isra-fel added a commit that referenced this issue May 15, 2023
#21765)

* Fixed Get-AzResourceGroup on -Id requires Set-AzContext to given subscription first [#21725]

* Update src/Resources/Resources/ChangeLog.md

Co-authored-by: Yeming Liu <[email protected]>

* revise code

* revise code

---------

Co-authored-by: Yeming Liu <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Azure PS Team bug This issue requires a change to an existing behavior in the product in order to be resolved. customer-reported Investigate 🔍
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants