msgraph-sdk-powershell
msgraph-sdk-powershell copied to clipboard
Setting Owner(s) with New-MgApplication and Update-MgApplication results in 'A change set cannot include changes to more than '1' source resources.'
Describe the bug
I am trying to create a new App registration, using New-MgApplication, setting DisplayName, Notes, RequiredResourceAccess, and Owners in the request:
$newAppRegistration = New-MgApplication -DisplayName <> -Notes <> -RequiredResourceAccess <> -Owners <>
The first three parameters work, but setting Owners results in an error: 'A change set cannot include changes to more than '1' source resources.'
The same behaviour is present in Update-MgApplication:
Update-MgApplication -ApplicationId <> -Owners <>
Expected behavior
Expected behaviour is that the App registration is created with Owners.
How to reproduce
The following code, using a valid DirectoryObjectId:
$DebugPreference = "Continue"
$newApplicationDisplayName = 'New application'
$OwnersDirectoryObjects = Get-MgDirectoryObject -DirectoryObjectId '<removed>'
$newAppRegistration = New-MgApplication `
-DisplayName $newApplicationDisplayName `
-Owners $OwnersDirectoryObjects
results in the following error: 'A change set cannot include changes to more than '1' source resources.'
SDK Version
2.17.0 and 2.18.0 tested
Latest version known to work for scenario above?
Unknown
Known Workarounds
A colleague of mine succesfully used New-MgApplicationOwnerByRef as a workaround.
Debug output
Complete debug output (PII removed) below:
DEBUG: [CmdletBeginProcessing]: - New-MgApplication begin processing with parameterSet 'CreateExpanded'.
DEBUG: [Authentication]: - AuthType: 'AppOnly', TokenCredentialType: 'ClientCertificate', ContextScope: 'Process', AppName: '<REMOVED>'.
DEBUG: [Authentication]: - Scopes: [Application.ReadWrite.All, CrossTenantInformation.ReadBasic.All, User.Read.All, ServicePrincipalEndpoint.ReadWrite.All, AppRoleAssignment.ReadWrite.All].
DEBUG: ============================ HTTP REQUEST ============================
HTTP Method:
POST
Absolute Uri:
https://graph.microsoft.com/v1.0/applications
Headers:
FeatureFlag : 00000043
Cache-Control : no-store, no-cache
User-Agent : Mozilla/5.0,(Windows NT 10.0; Microsoft Windows 10.0.19045; en-NL),PowerShell/2024.2.1
Accept-Encoding : gzip
SdkVersion : graph-powershell/2.17.0
client-request-id : <REMOVED>
Body:
{
"displayName": "New application",
"owners": [
{
"@odata.context": "https://graph.microsoft.com/v1.0/$metadata#directoryObjects/$entity",
"@odata.type": "#microsoft.graph.user",
"businessPhones": [],
"displayName": "<REMOVED>",
"givenName": "<REMOVED>",
"surname": "<REMOVED>",
"userPrincipalName": "<REMOVED>",
"id": "<REMOVED>"
}
]
}
DEBUG: ============================ HTTP RESPONSE ============================
Status Code:
BadRequest
Headers:
Cache-Control : no-cache
Vary : Accept-Encoding
Strict-Transport-Security : max-age=31536000
request-id : <REMOVED>
client-request-id : <REMOVED>
x-ms-ags-diagnostic : {"ServerInfo":{"DataCenter":"West Europe","Slice":"E","Ring":"5","ScaleUnit":"006","RoleInstance":"AM1PEPF00032D1F"}}
x-ms-resource-unit : 1
Date : Tue, 07 May 2024 11:04:40 GMT
Body:
{
"error": {
"code": "Request_BadRequest",
"message": "A change set cannot include changes to more than '1' source resources.",
"innerError": {
"date": "2024-05-07T11:04:41",
"request-id": "<REMOVED>",
"client-request-id": "<REMOVED>"
}
}
}
New-MgApplication_CreateExpanded: A change set cannot include changes to more than '1' source resources.
Status: 400 (BadRequest)
ErrorCode: Request_BadRequest
Date: 2024-05-07T11:04:41
Headers:
Cache-Control : no-cache
Vary : Accept-Encoding
Strict-Transport-Security : max-age=31536000
request-id : <REMOVED>
client-request-id : <REMOVED>
x-ms-ags-diagnostic : {"ServerInfo":{"DataCenter":"West Europe","Slice":"E","Ring":"5","ScaleUnit":"006","RoleInstance":"AM1PEPF00032D1F"}}
x-ms-resource-unit : 1
Date : Tue, 07 May 2024 11:04:40 GMT
DEBUG: [CmdletEndProcessing]: - New-MgApplication end processing.
Configuration
- OS / architecture:
OS Name Microsoft Windows 10 Enterprise
Version 10.0.19045 Build 19045
Other OS Description Not Available
OS Manufacturer Microsoft Corporation
System Type x64-based PC
> $PSVersionTable
Name Value
---- -----
PSVersion 7.4.2
PSEdition Core
GitCommitId 7.4.2
OS Microsoft Windows 10.0.19045
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
Other information
No response