-
Notifications
You must be signed in to change notification settings - Fork 211
Description
Describe the bug
The cmdlet:
Set-MgBetaUserLicense -UserId $adUser.Id -AddLicenses @{SkuId = $Sku.SkuId} -RemoveLicenses @()
gives error:
Set-MgBetaUserLicense_AssignExpanded: D:\Repos\PFIBDO-ADM-CloudConfiguration\scripts\aad\Configure-Licenses.ps1:261:25
Line |
261 | … Set-MgBetaUserLicense -UserId $adUser.Id -AddLicenses @(@ …
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| One or more parameters of the operation 'assignLicense' are missing from the request payload. The missing parameters are: removeLicenses. Status: 400
| (BadRequest) ErrorCode: Request_BadRequest Date: 2025-02-28T20:04:03 Headers: Cache-Control : no-cache Vary :
| Accept-Encoding Strict-Transport-Security : max-age=31536000 request-id : cffa816c-c9ce-468f-843b-0b38595f1df8 client-request-id
| : 32915540-5cf1-4543-a811-3bbb3ba324e5 x-ms-ags-diagnostic : {"ServerInfo":{"DataCenter":"Switzerland
| North","Slice":"E","Ring":"3","ScaleUnit":"000","RoleInstance":"ZR1PEPF00000664"}} Link :
| <https://developer.microsoft-tst.com/en-us/graph/changes?$filterby=beta,Users&from=2022-02-01&to=2022-03-01>;rel="deprecation";type="text/html" deprecation
| : Thu, 17 Feb 2022 23:59:59 GMT sunset : Sat, 17 Feb 2024 23:59:59 GMT x-ms-resource-unit : 1 Date
| : Fri, 28 Feb 2025 20:04:03 GMT
Recommendation: See service error codes: https://learn.microsoft.com/graph/errors
This code was working in the past.
Expected behavior
It should be possible to assing just a license without removing one. This has be done in the past by adding an empty array in the RemoveLicenses parameter like documented.
How to reproduce
Try to assign a license without removing one.
SDK Version
ModuleType Version PreRelease Name ExportedCommands ---------- ------- ---------- ---- ---------------- Script 2.26.1 Microsoft.Graph.Authentication {Add-MgEnvironment, Connect-MgGraph, Disconnect-MgGraph, Get-MgContext…} Script 2.26.1 Microsoft.Graph.Beta.Applications {Add-MgBetaApplicationKey, Add-MgBetaApplicationPassword, Add-MgBetaServicePrincipalTokenSigni… Script 2.26.1 Microsoft.Graph.Beta.Groups {Add-MgBetaGroupFavorite, Add-MgBetaGroupSiteContentModelGetByNameToDrive, Add-MgBetaGroupToLi… Script 2.26.1 Microsoft.Graph.Beta.Identity.Dire… {Complete-MgBetaDirectoryImpactedResource, Complete-MgBetaDirectoryRecommendation, Complete-Mg… Script 2.26.1 Microsoft.Graph.Beta.Identity.Gove… {Add-MgBetaAccessReviewDecision, Add-MgBetaAccessReviewInstanceDecision, Add-MgBetaIdentityGov… Script 2.26.1 Microsoft.Graph.Beta.Identity.Sign… {Confirm-MgBetaInformationProtectionSignature, Confirm-MgBetaRiskyServicePrincipalCompromised,… Script 2.26.1 Microsoft.Graph.Beta.Users {Complete-MgBetaUserOutlookTask, Complete-MgBetaUserOutlookTaskFolderTask, Complete-MgBetaUser… Script 2.26.1 Microsoft.Graph.Beta.Users.Actions {Clear-MgBetaUserAndBlockManagedApp, Clear-MgBetaUserManagedAppRegistrationByAzureAdDeviceId, …
Latest version known to work for scenario above?
2.25.X
Known Workarounds
Downgrading module could work may does not have to
Debug output
Click to expand log
```DEBUG: [CmdletBeginProcessing]: - Set-MgBetaUserLicense begin processing with parameterSet 'AssignExpanded'.
DEBUG: [Authentication]: - AuthType: 'Delegated', TokenCredentialType: 'InteractiveBrowser', ContextScope: 'CurrentUser', AppName: 'Microsoft Graph Command Line Tools'.
DEBUG: [Authentication]: - Scopes: [Application.ReadWrite.All, AppRoleAssignment.ReadWrite.All, AuditLog.Read.All, ChannelMessage.Send, Contacts.Read, CrossTenantInformation.ReadBasic.All, DelegatedPermissionGrant.ReadWrite.All, DeviceManagementApps.Read.All, DeviceManagementApps.ReadWrite.All, DeviceManagementConfiguration.Read.All, DeviceManagementConfiguration.ReadWrite.All, DeviceManagementManagedDevices.Read.All, DeviceManagementManagedDevices.ReadWrite.All, DeviceManagementRBAC.Read.All, DeviceManagementServiceConfig.Read.All, DeviceManagementServiceConfig.ReadWrite.All, Directory.AccessAsUser.All, Directory.Read.All, Directory.ReadWrite.All, Domain.ReadWrite.All, email, Group.ReadWrite.All, GroupMember.ReadWrite.All, openid, Organization.ReadWrite.All, OrganizationalBranding.ReadWrite.All, Policy.Read.All, Policy.ReadWrite.AuthenticationMethod, Policy.ReadWrite.Authorization, Policy.ReadWrite.ConditionalAccess, Policy.ReadWrite.CrossTenantAccess, Policy.ReadWrite.DeviceConfiguration, Policy.ReadWrite.PermissionGrant, profile, RoleAssignmentSchedule.ReadWrite.Directory, RoleEligibilitySchedule.Read.Directory, RoleEligibilitySchedule.ReadWrite.Directory, RoleManagement.Read.All, RoleManagement.ReadWrite.Directory, SharePointTenantSettings.ReadWrite.All, TeamMember.ReadWrite.All, TeamsApp.ReadWrite.All, TeamsAppInstallation.ReadWriteForTeam, TeamsAppInstallation.ReadWriteSelfForTeam, TeamSettings.ReadWrite.All, TeamsTab.ReadWrite.All, User.Read.All, User.ReadWrite.All, UserAuthenticationMethod.Read.All, UserAuthenticationMethod.ReadWrite.All, WindowsUpdates.ReadWrite.All].
Confirm
Are you sure you want to perform this action?
Performing the operation "Set-MgBetaUserLicense_AssignExpanded" on target "Call remote 'POST /users/{user-id}/microsoft.graph.assignLicense' operation".
[Y] Yes [A] Yes to All [N] No [L] No to All [S] Suspend [?] Help (default is "Y"): A
DEBUG: ============================ HTTP REQUEST ============================
HTTP Method:
POST
Absolute Uri:
https://graph.microsoft.com/beta/users/0e88beff-7c45-4bc2-9631-bca7e7e0908b/microsoft.graph.assignLicense
Headers:
FeatureFlag : 00000003
Cache-Control : no-store, no-cache
User-Agent : Mozilla/5.0,(Windows NT 10.0; Microsoft Windows 10.0.26100; de-CH),PowerShell/2025.0.0
SdkVersion : graph-powershell-beta/2.26.1
client-request-id : fb641a05-b41d-4fb6-ab26-24d6bb4974d9
Accept-Encoding : gzip,deflate,br
Body:
{
"addLicenses": [
{
"skuId": "f245ecc8-75af-4f8e-b61f-27d8114de5f3"
}
]
}
DEBUG: ============================ HTTP RESPONSE ============================
Status Code:
BadRequest
Headers:
Cache-Control : no-cache
Vary : Accept-Encoding
Strict-Transport-Security : max-age=31536000
request-id : 974af0e7-9da6-49f6-83e8-c257c2b9a881
client-request-id : fb641a05-b41d-4fb6-ab26-24d6bb4974d9
x-ms-ags-diagnostic : {"ServerInfo":{"DataCenter":"Switzerland North","Slice":"E","Ring":"3","ScaleUnit":"000","RoleInstance":"ZR1PEPF0000066C"}}
Link : https://developer.microsoft-tst.com/en-us/graph/changes?$filterby=beta,Users&from=2022-02-01&to=2022-03-01;rel="deprecation";type="text/html"
deprecation : Thu, 17 Feb 2022 23:59:59 GMT
sunset : Sat, 17 Feb 2024 23:59:59 GMT
x-ms-resource-unit : 1
Date : Fri, 28 Feb 2025 20:06:39 GMT
Body:
{
"error": {
"code": "Request_BadRequest",
"message": "One or more parameters of the operation 'assignLicense' are missing from the request payload. The missing parameters are: removeLicenses.",
"innerError": {
"date": "2025-02-28T20:06:39",
"request-id": "974af0e7-9da6-49f6-83e8-c257c2b9a881",
"client-request-id": "fb641a05-b41d-4fb6-ab26-24d6bb4974d9"
}
}
}
Set-MgBetaUserLicense_AssignExpanded: D:\Repos\PFIBDO-ADM-CloudConfiguration\scripts\aad\Configure-Licenses.ps1:261:25
Line |
261 | … Set-MgBetaUserLicense -UserId $adUser.Id -AddLicenses @(@ …
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| One or more parameters of the operation 'assignLicense' are missing from the request payload. The missing parameters are: removeLicenses. Status: 400
| (BadRequest) ErrorCode: Request_BadRequest Date: 2025-02-28T20:06:39 Headers: Cache-Control : no-cache Vary :
| Accept-Encoding Strict-Transport-Security : max-age=31536000 request-id : 974af0e7-9da6-49f6-83e8-c257c2b9a881 client-request-id
| : fb641a05-b41d-4fb6-ab26-24d6bb4974d9 x-ms-ags-diagnostic : {"ServerInfo":{"DataCenter":"Switzerland
| North","Slice":"E","Ring":"3","ScaleUnit":"000","RoleInstance":"ZR1PEPF0000066C"}} Link :
| https://developer.microsoft-tst.com/en-us/graph/changes?$filterby=beta,Users&from=2022-02-01&to=2022-03-01;rel="deprecation";type="text/html" deprecation
| : Thu, 17 Feb 2022 23:59:59 GMT sunset : Sat, 17 Feb 2024 23:59:59 GMT x-ms-resource-unit : 1 Date
| : Fri, 28 Feb 2025 20:06:39 GMT
Recommendation: See service error codes: https://learn.microsoft.com/graph/errors
</details>
### Configuration
PS D:\Repos\PFIBDO-ADM-CloudConfiguration> $PSVersionTable
Name Value
---- -----
PSVersion 7.5.0
PSEdition Core
GitCommitId 7.5.0
OS Microsoft Windows 10.0.26100
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
Architecture: x64
### Other information
_No response_