Set-MsolUserLicense -RemoveLicense Issue

This topic contains 1 reply, has 2 voices, and was last updated by  postanote 3 weeks, 1 day ago.

  • Author
    Posts
  • #103474

    Roy
    Participant

    I am trying to an-assign a bulk of user's licenses from our Office365.

    I have all of the user's UserPrincipalName on a CSV file like so:
    Name
    user.name@domain.com
    user.name2@domain.com

    That is what I tried to do:

    $csv1 = import-csv | select -expandProperty name
    Set-MsolUserLicense -UserPrincipalName $csv1 -RemoveLicense "domain:STANDARDPACK"

    When I had only ONE user on the CSV file, IT WORKED! But when I tried to add more users to the exact file and in the exact same list, the command fails and give me this error:

    Set-MsolUserLicense : Unable to assign this license because it is invalid. Use the Get-MsolAccountSku cmdlet to retrieve a list of valid licenses.

    I doubled checked and made sure it is indeed the correct license (domain:StandartPack)

    What else can I do? How can I make it work?

    Thanks,

  • #103478

    postanote
    Participant

    You are not looping through the user list in the CSV file.
    $csv1 is not a use name, it's a lot of user names and you can only pass one name at a time.

    # Collect all the user names to provision
    $csv1 = import-csv | select -expandProperty name
    
    # step through each user and take actions needed.
    ForEach($MSOUser in $csv1)
    { 
        # your code here'
    }
    

    There is a script on the MS powershellgallery.com that does this. See if that can replace the effort you are trying.

    Bulk license assignment to Office 365 users based on CSV

    If you have directory synchronization in place, your identities get provisioned in Office 365 without a license. You can use this script to bulk-add the licenses to the users based on a CSV file.

    'gallery.technet.microsoft.com/office/Bulk-license-assignment-to-ef16531b'

    There are other approaches, depending on how you need to do this.

    How to Use PowerShell to Automatically Assign Licenses to Your Office 365 Users
    'social.technet.microsoft.com/wiki/contents/articles/15905.how-to-use-powershell-to-automatically-assign-licenses-to-your-office-365-users.aspx'

    Bulk assign custom Office 365 licenses via Powershell
    'blogoffice365.com/bulk-assign-custom-office-365-licenses-via-powershell'

    Bulk Assign Licenses in Office 365 Using PowerShell
    'joshheffner.com/bulk-assign-licenses-in-office-365-using-powershell'

    Assign licenses to user accounts with Office 365 PowerShell
    'docs.microsoft.com/en-us/office365/enterprise/powershell/assign-licenses-to-user-accounts-with-office-365-powershell'

You must be logged in to reply to this topic.