Forum Discussion

VBardV's avatar
VBardV
Copper Contributor
Nov 23, 2023

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.

    • VBardV's avatar
      VBardV
      Copper 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.

      • LainRobertson's avatar
        LainRobertson
        Silver Contributor

        VBardV 

         

        The only other meaning that error encompasses is that the user provided in the $_.UPN reference does not exist.

         

        Cheers,

        Lain

Resources