Azure / Azure/azure-powershell
New-AzADServicePrincipal -DisplayName 'Something' Error - queried reference-property objects are not present.
- Dominant language
- C#
- Stars
- 4.8k
- Forks
- 4.3k
- Avg merge
- 2d 17h
- Merged PRs (30d)
- 51
Description
### Description
Not sure if this i related to our environment or something else, but starting this month, we see some issues when creating SPN with command New-AzADServicePrincipal
The running command stopped because the preference variable "ErrorActionPreference" or common parameter is set to Stop: Resource '79d705cd-542f-4639-9973-xxxx' does not exist or one of its queried reference-property objects are not present.
At /usr/local/share/powershell/Modules/Az.Resources/8.1.1/MSGraph.Autorest/custom/New-AzADAppCredential.ps1:265 char:17
During this Az APP registration is created without credentials, but next step fails ...
We have Linux and Windows runners, with different version of PS. I tried also older or latest version of Az.resources 9.x same issue. PS 7.4 Linux and 7.6 on windows, same issue ..
I tried to create SPN with Azure CLI to see if there is issue with permission, and this worked.
But on second try I noticed similar message, but SPN was created correctly.
az ad sp create-for-rbac -n "DisplayName" --create-password false
WARNING: Creating service principal failed with error 'The appId 'XXXX-XXX-XXX-XXXX-XXXXXX' of the service principal does not reference a valid application object.'. Retrying: 1/36
{
"appId": "XXXX-XXX-XXX-XXXX-XXXXXX",
So I expect similar core issue, maybe on MSGraph, but azure cli is doing internally some retry and then this works??
Maybe some throttling?
I also tried to create AzAPP first then use this azAD app to create SPN but there was another error, related to credentials.
### Issue script & Debug output
```PowerShell
New-AzADServicePrincipal -DisplayName 'Something'
The running command stopped because the preference variable "ErrorActionPreference" or common parameter is set to Stop: Resource 'XXXXX-XXXXX-XXX-XXX-XXXXXXX' does not exist or one of its queried reference-property objects are not present.
At /usr/local/share/powershell/Modules/Az.Resources/8.1.1/MSGraph.Autorest/custom/New-AzADAppCredential.ps1:265 char:17
+ … Az.MSGraph.internal\Add-AzADApplicationPassword @PSBoundP …
```
### Environment data
```PowerShell
Name Value
---- -----
PSVersion 7.4.14
PSEdition Core
GitCommitId 7.4.14
OS Ubuntu 24.04.4 LTS
Platform Unix
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
```
### Module versions
```PowerShell
Az 14.6.0
Az.Accounts 5.3.4
Az.Advisor 2.1.1
Az.Aks 7.0.0
Az.AnalysisServices 1.2.0
Az.ApiManagement 4.1.0
Az.App 2.0.1
Az.AppConfiguration 2.0.0
Az.ApplicationInsights 2.3.1
Az.ArcResourceBridge 1.1.1
Az.ArizeAI 1.0.0
Az.Attestation 2.1.1
Az.Automanage 1.1.1
Az.MarketplaceOrdering 2.2.0
Az.Migrate 2.10.1
Az.Monitor 6.0.3
Az.MySql 1.5.0
Az.Network 7.23.0
Az.NetworkCloud 1.2.1
Az.Nginx 1.2.1
Az.NotificationHubs 1.2.0
Az.OperationalInsights 3.3.0
Az.Oracle 1.2.0
Az.PolicyInsights 1.7.1
Az.PostgreSql 1.4.0
Az.PowerBIEmbedded 2.1.0
Az.PrivateDns 1.2.0
Az.RecoveryServices 7.10.0
Az.RedisCache 1.11.0
Az.RedisEnterpriseCache 1.6.0
Az.Relay 2.1.2
Az.ResourceGraph 1.2.1
Az.ResourceMover 1.3.1
Az.Resources 8.1.1
Az.Security 1.8.0
Az.SecurityInsights 3.2.1
Az.ServiceBus 4.1.1
Az.ServiceFabric 3.8.0
Az.SignalR 2.3.0
Az.Sql 6.3.0
Az.SqlVirtualMachine 2.4.0
Az.StackHCI 2.6.4
Az.StackHCIVM 1.1.0
Az.Storage 9.3.0
Az.StorageAction 1.0.0
Az.StorageDiscovery 1.0.0
Az.StorageMover 1.6.0
Az.StorageSync 2.5.2
Az.StreamAnalytics 2.1.1
Az.Subscription 0.12.0
Az.Support 2.1.0
Az.Synapse 3.2.2
Az.TrafficManager 1.3.0
Az.Websites 3.4.2
Az.Workloads 1.0.1
```
### Error output
```PowerShell
N/A -> As we run this inside a pipeline job, and job was terminated on error. This was not executed. I tried to use -ErrorAction SilentlyContinue but didn't help.
```
Contributor guide
Research direction
Start by reproducing New-AzADServicePrincipal -DisplayName 'Something' in the reported PowerShell environments and inspect the failure at MSGraph.Autorest/custom/New-AzADAppCredential.ps1 line 265. Compare the service-principal creation flow with the Azure CLI behavior; done means the command creates the service principal with credentials without the queried reference-property error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- azure, powershell
- Domain
- authentication, cloud
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100