@@ -358,8 +358,15 @@ try {
358
358
# Make sure the provisioner OID is set so we can pass it through to the deployment.
359
359
if (! $ProvisionerApplicationId -and ! $ProvisionerApplicationOid ) {
360
360
if ($context.Account.Type -eq ' User' ) {
361
- # HomeAccountId format is '<object id>.<tenant id>'
362
- $userAccountId = (Get-AzContext ).Account.ExtendedProperties.HomeAccountId.Split(' .' )[0 ]
361
+ # Calls to graph API in corp tenant get blocked by conditional access policy now
362
+ # but not in TME. For corp tenant we get the user's id from the login context
363
+ # but for TME it is different so we have to source it from graph
364
+ $userAccountId = if ($wellKnownTMETenants.Contains ($TenantId )) {
365
+ (Get-AzADUser - SignedIn).Id
366
+ } else {
367
+ # HomeAccountId format is '<object id>.<tenant id>'
368
+ (Get-AzContext ).Account.ExtendedProperties.HomeAccountId.Split(' .' )[0 ]
369
+ }
363
370
if ($null -eq $userAccountId ) {
364
371
throw " Failed to find entra object ID for the current user"
365
372
}
@@ -430,12 +437,20 @@ try {
430
437
431
438
if (! $CI -and ! $ServicePrincipalAuth ) {
432
439
if ($TestApplicationId ) {
433
- Write-Warning " The specified TestApplicationId '$TestApplicationId ' will be ignored when -ServicePrincipalAutth is not set."
440
+ Write-Warning " The specified TestApplicationId '$TestApplicationId ' will be ignored when -ServicePrincipalAuth is not set."
434
441
}
435
442
436
443
$userAccountName = (Get-AzContext ).Account.Id
437
444
# HomeAccountId format is '<object id>.<tenant id>'
438
- $userAccountId = (Get-AzContext ).Account.ExtendedProperties.HomeAccountId.Split(' .' )[0 ]
445
+ # Calls to graph API in corp tenant get blocked by conditional access policy now
446
+ # but not in TME. For corp tenant we get the user's id from the login context
447
+ # but for TME it is different so we have to source it from graph
448
+ $userAccountId = if ($wellKnownTMETenants.Contains ($TenantId )) {
449
+ (Get-AzADUser - SignedIn).Id
450
+ } else {
451
+ # HomeAccountId format is '<object id>.<tenant id>'
452
+ (Get-AzContext ).Account.ExtendedProperties.HomeAccountId.Split(' .' )[0 ]
453
+ }
439
454
if ($null -eq $userAccountId ) {
440
455
throw " Failed to find entra object ID for the current user"
441
456
}
0 commit comments