Closed kwill-MSFT closed 6 months ago
Thanks for the feedback @kwil-MSFT ! We'd like to understand better about your scenario. Is it possible to share the whole script (internally if it contains sensitive info)? We are particularly interested in how you authenticate for different tenants and how you utilize multi-thread, how they cooperate with each other as well.
cc @dolauli
Misspelled the user name ... @kwill-MSFT could you share your scenario or script? Thanks.
Hi, we're sending this friendly reminder because we haven't heard back from you in a while. We need more information about this issue to help address it. Please be sure to give us your input within the next 7 days. If we don't hear back from you within 14 days of this comment the issue will be automatically closed. Thank you!
Provided additional context and details internally.
Simple repro:
$SubId1 = "1237f4d2-3dce-4b96-ad95-677f764e7123"
$TenantId1 = "123988bf-86f1-41af-91ab-2d7cd011d123"
$SubId2 = "123b7f32-b384-448e-ab45-98eb07d12123"
$TenantId2 = "12306220-b94c-4f6b-b120-59bda4a79123"
$Aggregation = @{
totalCost = @{
name = "Cost"
function = "Sum"
}
}
$DebugPreference = 'continue'
$ctx1 = Connect-AzAccount -Tenant $TenantId1 -Subscription $SubId1
#This works because the current context is Tenant1
Invoke-AzCostManagementQuery -Scope "/subscriptions/$SubId1" -Timeframe 'MonthToDate' -Type 'ActualCost' -DatasetGranularity 'Monthly' -DatasetAggregation $Aggregation -DefaultProfile $ctx1
$ctx2 = Connect-AzAccount -Tenant $TenantId2 -Subscription $SubId2
#This fails with InvalidAuthenticationTokenTenant because I am trying to use the -DefaultProfile $ctx1 from Tenant1, but the current PS context is Tenant2
Invoke-AzCostManagementQuery -Scope "/subscriptions/$SubId1" -Timeframe 'MonthToDate' -Type 'ActualCost' -DatasetGranularity 'Monthly' -DatasetAggregation $Aggregation -DefaultProfile $ctx1
Description
We use -DefaultProfile to pass in contexts mapped to the different tenants we are targeting. This works fine for most Az cmdlets, but Invoke-AzCostManagementQuery ignores this -DefaultProfile parameter and just uses whatever context was last set for the Powershell session (ie. the last Connect-AzAccount).
This makes Invoke-AzCostManagementQuery unusable in multi-threaded scenarios where different threads are executing against different contexts.
Issue script & Debug output
Environment data
Module versions
Error output
No response