Azure / Azure/azure-powershell
Unable to retrieve PrincipalId for resource: The property 'PrincipalId' cannot be found on this object.
- Dominant language
- C#
- Stars
- 4.8k
- Forks
- 4.3k
- Avg merge
- 2d 17h
- Merged PRs (30d)
- 51
Description
### Description
Hello, I have a resource that is being retrieved with `Get-AzResource`. This is on an azure pipeline, as part of a role assignment for an azure app function.
I can see the `$resource.Identity.PrincipalId` when printing the Identity property, but when I get the PrincipalId property itself I get the following exception:
`System.Management.Automation.PropertyNotFoundException: The property 'PrincipalId' cannot be found on this object. Verify that the property exists.`
I can query the PrincipalId fine when examining the object from a local powershell instance, but the pipeline always fails for this resource.
### Issue script & Debug output
```PowerShell
[33;1mDEBUG: 04:54:12 - GetAzureResourceCmdlet begin processing with ParameterSet 'ByTagNameValueParameterSet'.[0m
[33;1mDEBUG: 04:54:12 - using account id '***'...[0m
[33;1mDEBUG: [Common.Authentication]: Authenticating using Account: '***', environment: 'AzureCloud', tenant: 'REDACTED'[0m
2024-09-18T04:54:13.1384013Z [33;1mDEBUG: 04:54:12 - [ServicePrincipalAuthenticator] Calling ClientSecretCredential.GetTokenAsync - ApplicationId:'***', TenantId:'REDACTED', Scopes:'https://management.core.rityHost:'https://login.microsoftonline.com/'[0m
[33;1mDEBUG: ClientSecretCredential.GetToken invoked. Scopes: [ https://management.core.windows.net//.default ] ParentRequestId: [0m
[33;1mDEBUG: Request [b7f13c47-0810-4768-922a-2a4cd9cfa0a7] POST https://login.microsoftonline.com/REDACTED/oauth2/v2.0/token
x-client-SKU:REDACTED
x-client-Ver:REDACTED
x-client-OS:REDACTED
x-client-current-telemetry:REDACTED
x-client-last-telemetry:REDACTED
x-ms-PKeyAuth:REDACTED
x-ms-lib-capability:REDACTED
client-request-id:REDACTED
return-client-request-id:REDACTED
x-app-name:REDACTED
x-app-ver:REDACTED
x-ms-client-request-id:b7f13c47-0810-4768-922a-2a4cd9cfa0a7
x-ms-return-client-request-id:true
User-Agent:azsdk-net-Identity/1.4.0,(.NET 8.0.8; Ubuntu 22.04.4 LTS)
Content-Type:application/x-www-form-urlencoded
client assembly: Azure.Identity[0m
[33;1mDEBUG: Response [b7f13c47-0810-4768-922a-2a4cd9cfa0a7] 200 OK (00.4s)
Cache-Control:no-store, no-cache
Pragma:no-cache
Strict-Transport-Security:REDACTED
X-Content-Type-Options:REDACTED
P3P:REDACTED
client-request-id:REDACTED
x-ms-request-id:b11fb720-cde0-486a-9ab9-4c05e23e6600
x-ms-ests-server:REDACTED
x-ms-clitelem:REDACTED
x-ms-srs:REDACTED
X-XSS-Protection:REDACTED
Set-Cookie:REDACTED
Date:Wed, 18 Sep 2024 04:54:12 GMT
Content-Type:application/json; charset=utf-8
Expires:-1
Content-Length:11559
[0m
[33;1mDEBUG: ClientSecretCredential.GetToken succeeded. Scopes: [ https://management.core.windows.net//.default ] ParentRequestId: ExpiresOn: 2024-09-18T05:54:11.0000000+00:00[0m
[33;1mDEBUG: [Common.Authentication]: Received token with LoginType 'User', Tenant: 'REDACTED', UserId: '***'[0m
[33;1mDEBUG: ============================ HTTP REQUEST ============================
HTTP Method:
GET
Absolute Uri:
https://management.azure.com/subscriptions/REDACTED/resourceGroups/REDACTED/resources?api-version=2021-04-01
Headers:
Accept-Language : en-US
x-ms-client-request-id : 3877c295-4424-480d-9a4c-edbbb1f887e5
Body:
[0m
[33;1mDEBUG: ============================ HTTP RESPONSE ============================
Status Code:
OK
Headers:
Cache-Control : no-cache
Pragma : no-cache
x-ms-ratelimit-remaining-subscription-reads: 499
x-ms-ratelimit-remaining-subscription-global-reads: 7499
x-ms-request-id : 3543e8f1-d4c0-4dbb-9929-4f7f3bfb8577
x-ms-correlation-request-id : 3543e8f1-d4c0-4dbb-9929-4f7f3bfb8577
x-ms-routing-request-id : WESTUS:20240918T045413Z:3543e8f1-d4c0-4dbb-9929-4f7f3bfb8577
Strict-Transport-Security : max-age=31536000; includeSubDomains
X-Content-Type-Options : nosniff
X-Cache : CONFIG_NOCACHE
X-MSEdge-Ref : Ref A: 74936954AED94059A67AAFEDF3CF380A Ref B: SJC211051205021 Ref C: 2024-09-18T04:54:12Z
Date : Wed, 18 Sep 2024 04:54:13 GMT
Body:
{
"value": [
{
"id": "/subscriptions/REDACTED/resourceGroups/REDACTED/providers/Microsoft.Storage/storageAccounts/REDACTED",
"name": "REDACTED",
"type": "Microsoft.Storage/storageAccounts",
"sku": {
"name": "Standard_LRS",
"tier": "Standard"
},
"kind": "StorageV2",
"location": "southeastasia",
"identity": {
"principalId": "REDACTED",
"tenantId": "REDACTED",
"type": "SystemAssigned"
},
"tags": {
"client": "internal",
"cost_center": "internaltestenv",
"environment": "REDACTED",
"owner": "REDACTED",
"system": "REDACTED",
"pipeline": "REDACTED Function App"
}
},
{
"id": "/subscriptions/REDACTED/resourceGroups/REDACTED/providers/Microsoft.Web/serverFarms/REDACTED",
"name": "REDACTED",
"type": "Microsoft.Web/serverFarms",
"sku": {
"name": "Y1",
"tier": "Dynamic",
"size": "Y1",
"family": "Y",
"capacity": 0
},
"kind": "functionapp",
"location": "southeastasia",
"tags": {}
},
{
"id": "/subscriptions/REDACTED/resourceGroups/REDACTED/providers/Microsoft.Web/sites/REDACTED",
"name": "REDACTED",
"type": "Microsoft.Web/sites",
"kind": "functionapp",
"location": "southeastasia",
"identity": {
"principalId": "REDACTED",
"tenantId": "REDACTED",
"type": "SystemAssigned"
},
"tags": {
"client": "internal",
"cost_center": "internaltestenv",
"environment": "REDACTED",
"owner": "REDACTED",
"system": "REDACTED",
"pipeline": "REDACTED"
}
},
{
"id": "/subscriptions/REDACTED/resourceGroups/REDACTED/providers/Microsoft.Web/sites/REDACTED/slots/staging",
"name": "int-dev2-pos-reingester-func/staging",
"type": "Microsoft.Web/sites/slots",
"kind": "functionapp",
"location": "southeastasia",
"identity": {
"principalId": "REDACTED",
"tenantId": "REDACTED",
"type": "SystemAssigned"
},
"tags": {
"client": "internal",
"cost_center": "internaltestenv",
"environment": "REDACTED",
"owner": "REDACTED",
"system": "REDACTED",
"pipeline": "REDACTED Function App"
}
},
{
"id": "/subscriptions/REDACTED/resourceGroups/REDACTED/providers/microsoft.insights/components/REDACTED",
"name": "int-dev2-pos-reingester-func",
"type": "microsoft.insights/components",
"kind": "web",
"location": "southeastasia",
"tags": {}
},
{
2024-09-18T04:54:13.1455740Z "id": "/subscriptions/REDACTED/resourceGroups/REDACTED/providers/microsoft.alertsmanagement/smartDetectorAlertRules/Failure Anomalies - ,
"name": "Failure Anomalies - REDACTED",
"type": "microsoft.alertsmanagement/smartDetectorAlertRules",
"location": "global",
"tags": {}
}
]
}
[0m
[33;1mDEBUG: AzureQoSEvent: Module: Az.Resources:4.4.0; CommandName: Get-AzResource; PSVersion: 7.4.5; IsSuccess: True; Duration: 00:00:00.7623509[0m
[33;1mDEBUG: Finish sending metric.[0m
[33;1mDEBUG: 04:54:13 - GetAzureResourceCmdlet end processing.[0m
```
### Environment data
```PowerShell
PSVersionTable:
Key : PSVersion
Value : 7.4.5
Name : PSVersion
Key : PSEdition
Value : Core
Name : PSEdition
Key : GitCommitId
Value : 7.4.5
Name : GitCommitId
Key : OS
Value : Ubuntu 22.04.4 LTS
Name : OS
Key : Platform
Value : Unix
Name : Platform
Key : PSCompatibleVersions
Value : {1.0, 2.0, 3.0, 4.0…}
Name : PSCompatibleVersions
Key : PSRemotingProtocolVersion
Value : 2.3
Name : PSRemotingProtocolVersion
Key : SerializationVersion
Value : 1.1.0.1
Name : SerializationVersion
Key : WSManStackVersion
Value : 3.0
Name : WSManStackVersion
```
### Module versions
```PowerShell
Name : Az.Accounts
Path : /usr/share/az_6.5.0/Az.Accounts/2.5.4/Az.Accounts.psm1
Description : Microsoft Azure PowerShell - Accounts credential management
cmdlets for Azure Resource Manager in Windows PowerShell a
nd PowerShell Core.
For more information on account credential management, plea
se visit the following: https://docs.microsoft.com/powershe
ll/azure/authenticate-azureps
Guid : 17a2feff-488b-47f9-8729-e2cec094624c
Version : 2.5.4
ModuleBase : /usr/share/az_6.5.0/Az.Accounts/2.5.4
ModuleType : Script
PrivateData : {[PSData, System.Collections.Hashtable]}
AccessMode : ReadWrite
ExportedAliases : {[Add-AzAccount, Add-AzAccount], [Get-AzDomain, Get-AzDomai
n], [Invoke-AzRest, Invoke-AzRest], [Login-AzAccount, Login
-AzAccount]…}
ExportedCmdlets : {[Add-AzEnvironment, Add-AzEnvironment], [Clear-AzContext,
Clear-AzContext], [Clear-AzDefault, Clear-AzDefault], [Conn
ect-AzAccount, Connect-AzAccount]…}
ExportedFunctions : {}
ExportedVariables : {}
NestedModules : {Microsoft.Azure.PowerShell.Cmdlets.Accounts}
Name : Az.Resources
Path : /usr/share/az_6.5.0/Az.Resources/4.4.0/Az.Resources.psm1
Description : Microsoft Azure PowerShell - Azure Resource Manager and Act
ive Directory cmdlets in Windows PowerShell and PowerShell
Core. Manages subscriptions, tenants, resource groups, dep
loyment templates, providers, and resource permissions in A
zure Resource Manager. Provides cmdlets for managing resou
rces generically across resource providers.
For more information on Resource Manager, please visit the
following: https://docs.microsoft.com/azure/azure-resource-
manager/
For more information on Active Directory, please visit the
following: https://docs.microsoft.com/azure/active-director
y/fundamentals/active-directory-whatis
Guid : 48bb344d-4c24-441e-8ea0-589947784700
Version : 4.4.0
ModuleBase : /usr/share/az_6.5.0/Az.Resources/4.4.0
ModuleType : Script
PrivateData : {[PSData, System.Collections.Hashtable]}
AccessMode : ReadWrite
ExportedAliases : {[Get-AzADServicePrincipalCredential, Get-AzADServicePrinci
palCredential], [Get-AzResourceProviderAction, Get-AzResour
ceProviderAction], [Get-AzSubscriptionDeployment, Get-AzSub
scriptionDeployment], [Get-AzSubscriptionDeploymentOperatio
n, Get-AzSubscriptionDeploymentOperation]…}
ExportedCmdlets : {[Add-AzADGroupMember, Add-AzADGroupMember], [Export-AzReso
urceGroup, Export-AzResourceGroup], [Export-AzTemplateSpec,
Export-AzTemplateSpec], [Get-AzADAppCredential, Get-AzADAp
pCredential]…}
ExportedFunctions : {}
ExportedVariables : {}
NestedModules : {Microsoft.Azure.PowerShell.Cmdlets.Resources, Microsoft.Az
ure.PowerShell.Cmdlets.ResourceManager, Microsoft.Azure.Pow
erShell.Cmdlets.Tags}
```
### Error output
```PowerShell
InnerException : False
Exception : System.Management.Automation.PropertyNotFoundException: The
property 'PrincipalId' cannot be found on this object. Verif
y that the property exists.
at System.Management.Automation.ExceptionHandlingOps.Chec
kActionPreference(FunctionContext funcContext, Exception exc
eption)
at System.Management.Automation.Interpreter.ActionCallIns
truction`2.Run(InterpretedFrame frame)
at System.Management.Automation.Interpreter.EnterTryCatch
FinallyInstruction.Run(InterpretedFrame frame)
at System.Management.Automation.Interpreter.EnterTryCatch
FinallyInstruction.Run(InterpretedFrame frame)
Message : The property 'PrincipalId' cannot be found on this object. V
erify that the property exists.
StackTrace : at System.Management.Automation.ExceptionHandlingOps.Chec
kActionPreference(FunctionContext funcContext, Exception exc
eption)
at System.Management.Automation.Interpreter.ActionCallIns
truction`2.Run(InterpretedFrame frame)
at System.Management.Automation.Interpreter.EnterTryCatch
FinallyInstruction.Run(InterpretedFrame frame)
at System.Management.Automation.Interpreter.EnterTryCatch
FinallyInstruction.Run(InterpretedFrame frame)
HelpLink :
ErrorDetails :
ErrorCategory : NotSpecified: (:) [], PropertyNotFoundException
InvocationInfo : System.Management.Automation.InvocationInfo
ScriptStackTrace : at , /home/vsts/work/1/drop/Add-ResourceToPermi
ssionGroup.ps1: line 20
at , /home/vsts/work/1/drop/Create-ResourceToRe
sourcePermission.ps1: line 25
at , /home/vsts/work/_temp/c039f1c7-7ce8-4502-a
2fb-2c8fc9ee76d5.ps1: line 4
at , : line 1
```
Contributor guide
Research direction
Start by reproducing Get-AzResource with PowerShell 7.4.5 on Ubuntu and Az.Resources 4.4.0, using the resource response and failing PrincipalId access described here. Compare the returned Identity object and direct property behavior across the affected resource types; done means PrincipalId retrieval behaves consistently in the pipeline scenario.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- azure, csharp, powershell
- Domain
- cli, cloud
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100