Forum Discussion
How do i change user's exchange license in bulk using csv?
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.
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