none
License Enabling Script

    Question

  • Hello everyone,

    I might be in the wrong place and I'll give it a try anyway.

    The following script has the following goal:
    1.  Enable Office 365 for my students.
    2.  Disable Lync for my students.

    I have a nightly routine that takes care of AD maintenance.  As part of that, if any new students were enrolled during the previous days, it creates the student accounts, home directory, etc.

    Now, I wrote another script that dumps new students accounts into text file, another powershell feeds off that text file and it is supposed to enable Office and disable Lync.  Here's the PS file:

    #This script checks for "NewUser1" file.  If it does not exist, then it will not run.
    #However, if exist it will run in order to activatge Office 365 License and
    #restrict Lync for student accounts.
     
    #Set Variables
    $desiredplan="test:STANDARDWOFFPACK_IW_STUDENT"
    $disabledplan="MCOSTANDARD"
     
    #The following lines will change the lincese plan for each user.  
    Connect-MsolService
    ForEach ($NewUser1 in Get-Content c:\scripts\NewUserList.txt)
     {
     Write-Host $NewUser1
     # $CurrentUser=Get-MsolUser -UserPrincipalName $NewUser1@domain.net
     $currentlicenses=$CurrentUser.licenses
     $licensestoremove=@()
     ForEach($o365license in $currentlicenses)
      {$licensestoremove+=$o365license.accountskuid}
     $myplan=New-MsolLicenseOptions -AccountSkuId $desiredplan -DisabledPlans $disabledplan
     #Set-MsolUserLicense -UserPrincipalName $CurrentUser.UserPrincipalName -RemoveLicenses $licensestoremove -AddLicenses $desiredplan -LicenseOptions $myplan
     Set-MsolUserLicense -UserPrincipalName $NewUser1@domain.net -RemoveLicenses $licensestoremove -AddLicenses $desiredplan -LicenseOptions $myplan
     }
     

    When I run this file as is, I get the following error message:

    PS C:\Scripts> .\Set-NewUsers.ps1
    123abc
    Set-MsolUserLicense : You must provide a required property: Parameter name: UsageLocation
    At C:\Scripts\Set-NewUsers.ps1:21 char:2
    +     Set-MsolUserLicense -UserPrincipalName $NewUser1@domain.net -RemoveLicen ...
    +    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : OperationStopped: (:) [Set-MsolUserLicense], MicrosoftOnlineException
        + FullyQualifiedErrorId : Microsoft.Online.Administration.Automation.RequiredPropertyNotSetException,Microsoft.Onl
       ine.Administration.Automation.SetUserLicense

    So, I add UsageLocation to it, Like this:
    Set-MsolUserLicense -UsageLocation "US" -UserPrincipalName $NewUser1@students.fusd.net -RemoveLicenses $licensestoremove -AddLicenses $desiredplan -LicenseOptions $myplan

    and I get the following error message:
    PS C:\Scripts> .\Set-NewUsers.ps1
    123abc
    Set-MsolUserLicense : A parameter cannot be found that matches parameter name 'UsageLocation'.
    At C:\Scripts\Set-NewUsers.ps1:21 char:22
    +     Set-MsolUserLicense -UsageLocation "US" -UserPrincipalName $NewUser1@domain.net
    +                         ~~~~~~~~~~~~~~
        + CategoryInfo          : InvalidArgument: (:) [Set-MsolUserLicense], ParameterBindingException
        + FullyQualifiedErrorId : NamedParameterNotFound,Microsoft.Online.Administration.Automation.SetUserLicense

    GRRRR!!!! First it doesn't work because it wants UsageLocation and when I add it, it doesn't work because it does not know about UsageLocation.

    Any help greatly appreciate it.

    Thanks.

    Monday, August 24, 2015 4:07 PM

Answers

  • UsageLocation is a parameter for Set-MsolUser, for example:

    Set-MsolUser -UserPrincipalName user@domain.com -UsageLocation US

    If you need more help with the licensing process just do a quick search on the internet, there are lots of scripts published.

    • Marked as answer by abdielh Thursday, August 27, 2015 5:58 PM
    Monday, August 24, 2015 7:28 PM

All replies

  • UsageLocation is a parameter for Set-MsolUser, for example:

    Set-MsolUser -UserPrincipalName user@domain.com -UsageLocation US

    If you need more help with the licensing process just do a quick search on the internet, there are lots of scripts published.

    • Marked as answer by abdielh Thursday, August 27, 2015 5:58 PM
    Monday, August 24, 2015 7:28 PM
  • Thank you Vasil.  I just added your line and problem solved.
    Thursday, August 27, 2015 5:58 PM