Forum Discussion
How do i change user's exchange license in bulk using csv?
Import-Csv "C:\bulk.csv" | ForEach-Object {Set-MgUserLicense -UserId $_.UPN -RemoveLicenses @("xxx") -AddLicenses @{}}
Import-Csv "C:\bulk.csv" | %{Set-MgUserLicense -UserId $_.UPN -AddLicenses @{} -RemoveLicenses @(SkuId = "xxx")}
+ CategoryInfo : InvalidOperation: ({ UserId = kiti...ionJsonSchema }:<>f__AnonymousType8`2) [Set-MgUserLicense_AssignExpanded1], RestException`1
+ FullyQualifiedErrorId : Request_ResourceNotFound,Microsoft.Graph.PowerShell.Cmdlets.SetMgUserLicense_AssignExpanded1
Set-MgUserLicense : Resource 'email address removed for privacy reasons ' does not exist or one of its queried reference-property objects are not present.
At line:1 char:36
+ ... lk.csv" | %{Set-MgUserLicense -UserId $_.UPN -RemoveLicenses @("xxx ...
I am having hundreds of users pending since Set-MsolUserLicense is not usable anymore.
Kindly help.
7 Replies
- Andres-BohrenSteel ContributorHow about Group Based Licensing?
https://learn.microsoft.com/en-us/entra/fundamentals/concept-group-based-licensing
Regards
Andres - LainRobertsonSilver Contributor
Hi.
You've used the wrong format for -RemoveLicenses, as it is supposed to be a string array, not a HashTable.
Example
Strictly-speaking, the error encompasses two reasons for failure, however, I've gone with the second reason for this reply since that's definitely a problem within your second command.
Cheers,
Lain
- VBardVCopper Contributor
Hi Lain,
Warm Greetings,
My apologies not sure how i got it the other way around. I've corrected the syntax and i'm able to remove a license for one user but the bulk command is not working.
Import-Csv "C:\bulk.csv" | %{Set-MgUserLicense -UserId $_.UPN -AddLicenses @{} -RemoveLicenses @("XXX")}
Error as per post below:
+ CategoryInfo : InvalidOperation: ({ UserId = rang...ionJsonSchema }:<>f__AnonymousType8`2) [Set-MgUserLicense_AssignExpanded1], RestException`1
+ FullyQualifiedErrorId : Request_ResourceNotFound,Microsoft.Graph.PowerShell.Cmdlets.SetMgUserLicense_AssignExpanded1
Set-MgUserLicense : Resource 'email address ' does not exist or one of its queried reference-property objects are not present.
At line:1 char:50
+ ... ach-Object {Set-MgUserLicense -UserId $_.UPN -AddLicenses @{} -Remove ...
Kindly advise.- LainRobertsonSilver Contributor
The only other thing I can see - and it's subtle - is that within your error message, the userPrincipalName has a trailing space, which points back to your CSV file being the problem.
The userPrincipalName must be completely accurate. Leading or trailing spaces will cause the user to not be found.
Cheers,
Lain