Office 365 User Provisioning and CSV_Parser.ps1

  • 7 Followers
  • 18 Replies |
  • This post has 0 verified answers |
Answered (Not Verified) This question has suggested answer(s)
Live.edu allows for the creation of new accounts using Powershell and the CSV_parser.ps1 file for batch creation.    Will this file also create new accounts in Office 365?    If so, what adjustments are necessary to include the License when the account is created?
  • Post Points: 35
All Replies
  • Hi Steve,

    Thanks for your post here. 

    In regard to the issue, if you want bulk create users in Office 365 using PowerShell, please try the steps below:

    1. connect PowerShell to Office 365.
    2. create a .csv file named NewUser.csv which contain the following attributes: UPN, DisplayName, FirstName, LastName, Password, License. Then add the users you want to create in the file.
    3. Type in “Import-Csv NewUser.csv | foreach { New-MsolUser  –UserPrincipalName   $_.UPN  –DisplayName   $_.DisplayName   -FirstName  $_.FirstName  –LastName  $_.LastName  –Password  $_.Password } ” in PowerShell to create users in bulk.
    4. then use the "Set-MsolUserLicense" command to assign a license to the user.

    To check the license type of your organization, you can type in “Get-MsolAccountSku” in PowerShell after you connect it to Exchange Online, you can then add the parameter in the license tab in the .csv file.

    Please feel free to post your updates here at your convenient time.

    Thanks,

    Neo Yu

     

    • Top 25 Contributor
    • Post Points: 0
  • Actually, the question is can the CSV_parser.ps1 file be used to create new accounts in Office 365?    If so, what adjustments are necessary to include the License when the account is created?   This is the link to the file used for Live.edu - help.outlook.com/.../Cc713521.aspx.

    • Not Ranked
    • Post Points: 0
  •  

    Hi Steve,

    Thanks for your updates.

    In regard to the issue, currently it’s not available to create users using the CSV_parser.ps1 file. If you want to bulk add user in Office 365, I suggest you to refer my last post using PowerShell, or you can create a CSV file and upload it to Office 365 for bulk add. For details, please refer to: Add multiple users with bulk import.

    Please note that if you want to add users in bulk using MOP(Microsoft Online Portal) instead of PowerShell, there will be a limitation that each CSV file can only import 250 users by default, which doesn’t apply to PowerShell. Please feel free to post your updates here at your convenient time.

    Thanks,

    Neo Yu

     

    • Top 25 Contributor
    • Post Points: 0
    Suggested by
  • Hi Steve,

    How are things going? Did the above posts answer the issue?

    Please feel free to post your updates here at your convenient time.

    Thanks,

    Neo Yu

     

    • Top 25 Contributor
    • Post Points: 0
  • After a whole day of trawling Google and the forums your bulk create user which includes password and license was exactly what I needed.  The errors came thick and fast as I tried to construct my CSV. I've had to give up. Here's the error I get.  If you can point me I'd be even more apreciative.

    Set-MsolUserLicense : The input object cannot be bound to any parameters for th

    e command either because the command does not take pipeline input or the input

    and its properties do not match any of the parameters that take pipeline input.

    At line:1 char:265

    + Import-Csv C:\Users\dave\Desktop\Office365files\StaffAndPupilsFeb13\y7pupils4

    .csv | foreach { New-MsolUser  -UserPrincipalName   $_.UPN  -DisplayName   $_.D

    isplayName   -FirstName  $_.FirstName  -LastName  $_.LastName  -Password  $_.Pa

    ssword |  Set-MsolUserLicense <<<<   -UserPrincipalName  $_.UPN   -AddLicenses

     $_.License }

       + CategoryInfo          : InvalidArgument: (Microsoft.Onlin...on.UserExten

      ded:PSObject) [Set-MsolUserLicense], ParameterBindingException

       + FullyQualifiedErrorId : InputObjectNotBound,Microsoft.Online.Administrat

      ion.Automation.SetUserLicense

    • Not Ranked
    • Post Points: 0
  • Hi Boledy,

    Sorry for the inconvenience here.

    It seems that the command “Set-MsolUserLicense” can’t be used when the new user being created. In this situation, I suggest you can first create the user using the .csv file with the script below:

     Import-Csv NewUser.csv | foreach { New-MsolUser –UserPrincipalName  $_.UPN  –DisplayName  $_.DisplayName  -FirstName  $_.FirstName  –LastName  $_.LastName  –Password  $_.Password }

    Then use the following script to assign licenses to the users:

      Get-MsolUser | Foreach {Set-MsolUserLicense -UserPrincipalName $_.UserPrincipalName -AddLicenses "package name”}

    Thanks,

    Neo Yu

     

    • Top 25 Contributor
    • Post Points: 0
  • Thanks for the reply. Running the command in your original posted form created the user accounts but gave th error that I listed for each user. What I didn't realise was that the users location was also not set. I tried using -UsageLocation GB but the term is not ecognised.  I also tried applying the license using Set-MsolUserLicense -UserPrincipalName user@contoso.com -usagelocation GB -AddLicenses "contoso:ENTERPRISEPACK" which also failed.

    Set-MsolUserLicense -UserPrincipalName user@contoso.com  -AddLicenses "contoso:ENTERPRISEPACK" worked but gave the error usagelocation not set.

    Get-MsolUser | Foreach {Set-MsolUserLicense -UserPrincipalName $_. UserPrincipalName -AddLicenses "package name”} gave the following error

    Set-MsolUserLicense : Cannot bind argument to parameter 'UserPrincipalName'

    because it is null.

    At line:1 char:55

    + Get-MsolUser | Set-MsolUserLicense -UserPrincipalName $_. UPN -AddLicenses

    "newl ...

    +                                                       ~~

       + CategoryInfo          : InvalidData: (:) [Set-MsolUserLicense], Paramete

      rBindingValidationException

       + FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,M

      icrosoft.Online.Administration.Automation.SetUserLicense

    So far I can create users from the CSV but I cant set thier location and I cant add the license from a CSV.  I may have to manually set the location and licenses for 1500 users longhand!

    Any further help even more apreciated

    • Not Ranked
    • Post Points: 0
  • Hi Boledy,

    The specific error message indicates that the parameter “UserPrincipalName” is null, I’ve copied your code and tested it on my side, I found that there is a space between “$_.” and “UserPrincipalName” (which shouldn't have it). This should be the cause why the script failed.

    Please modify the code and try again to see if the issue will be resolved.

    Thanks,

    Neo Yu

     

    • Top 25 Contributor
    • Post Points: 0
  • Still no joy.

    PS C:\windows\system32> Get-MsolUser | Set-MsolUserLicense -UserPrincipalName $_

    .UPN -AddLicenses "newl:STANDARDWOFFPACK_STUDENT"

    Set-MsolUserLicense : Cannot bind argument to parameter 'UserPrincipalName'

    because it is null.

    At line:1 char:55

    + Get-MsolUser | Set-MsolUserLicense -UserPrincipalName $_.UPN -AddLicenses

    "newla ...

    +                                                       ~~~~~~

       + CategoryInfo          : InvalidData: (:) [Set-MsolUserLicense], Paramete

      rBindingValidationException

       + FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,M

      icrosoft.Online.Administration.Automation.SetUserLicense

    • Not Ranked
    • Post Points: 0
  • I tried it again with the CSV import piped to the front and got a similar error:

    PS C:\windows\system32> Import-Csv C:\Users\y7pupils5.csv | Get-MsolUser | Set-MsolUserLicense -UserPrincipalNam

    e $_.UPN -AddLicenses "newl:STANDARDWOFFPACK_STUDENT"

    Set-MsolUserLicense : Cannot bind argument to parameter 'UserPrincipalName'

    because it is null.

    At line:1 char:139

    + ... rPrincipalName $_.UPN -AddLicenses

    "newl:STANDARDWOFFPACK_STUDENT"

    +                    ~~~~~~

       + CategoryInfo          : InvalidData: (:) [Set-MsolUserLicense], Paramete

      rBindingValidationException

       + FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,M

      icrosoft.Online.Administration.Automation.SetUserLicense

    I tried adding the license to an individual user with this which worked after I had set the users location.

    Set-MsolUserLicense -UserPrincipalName janedoe@contoso.com -addlicense "contosoco:STANDARDWOFFPACK_STUDENT"

    • Not Ranked
    • Post Points: 0
  • Here is the error I get if I don't manually set the location.

    PS C:\windows\system32> Set-MsolUserLicense -UserPrincipalName janedoe@contoso.com -addlicense "newl:STANDARDWOFFPACK_STUDENT"

    Set-MsolUserLicense : You must provide a required property: Parameter name:

    UsageLocation

    At line:1 char:1

    + Set-MsolUserLicense -UserPrincipalName janedoe@contoso.com

    -addlicense  ...

    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    ~~~

       + CategoryInfo          : OperationStopped: (:) [Set-MsolUserLicense], Mic

      rosoftOnlineException

       + FullyQualifiedErrorId : Microsoft.Online.Administration.Automation.Requi

      redPropertyNotSetException,Microsoft.Online.Administration.Automation.SetU

     serLicense

    • Not Ranked
    • Post Points: 0
  • There is some further information.  If i run the following commands on thier own they work:

    Import-Csv NewUser.csv | foreach { New-MsolUser –UserPrincipalName  $_.UPN  –DisplayName  $_.DisplayName  -FirstName  $_.FirstName  –LastName $_.LastName  –Password  $_.Password }

    Set-MsolUser -UserPrincipalName janedoe@contoso.com -UsageLocation GB

    Set-MsolUserLicense -UserPrincipalName janedoe@contoso.com -addlicense "contosoco:STANDARDWOFFPACK_STUDENT"

    But if I try to combine the last two lines into a command that  sets the location and adds the license using the CSV like this one:

    Import-Csv NewUser.csv | foreach { Set-MsolUserLicense -UserPrincipalName   $_.UPN  -UsageLocation GB –AddLicense   $_.License }

    OR

    Import-Csv NewUser.csv | foreach { Set-MsolUserLicense -UserPrincipalName   $_.UPN  -UsageLocation $_.UL –AddLicense   $_.License }

    I get the following error:

    Set-MsolUserLicense : A parameter cannot be found that matches parameter name

    'UsageLocation'.

    At line:1 char:144

    + ... Name   $_.UPN  -UsageLocation GB -AddLicense   $_.License }

    +                    ~~~~~~~~~~~~~~

       + CategoryInfo          : InvalidArgument: (:) [Set-MsolUserLicense], Para

      meterBindingException

       + FullyQualifiedErrorId : NamedParameterNotFound,Microsoft.Online.Administ

      ration.Automation.SetUserLicense

    It feels like I am nearly there with this.  I just can't see what I'm doing wrong with the CSV import.  Can you help please?

    • Not Ranked
    • Post Points: 0
  • Hi Boledy,

    In regard to the issue, you can set the “UsageLocation” attribute (which is not a parameter for the command “Set-MsolUserLicense”) when creating the new user. To do that, please try the scripts below:

     Import-Csv NewUser.csv | foreach { New-MsolUser –UserPrincipalName  $_.UPN  –DisplayName  $_.DisplayName  -FirstName  $_.FirstName  –LastName  $_.LastName  –Password  $_.Password  -UsageLocation  GB}

    Then assign license to the users using the following script:

     Get-MsolUser | Foreach {Set-MsolUserLicense -UserPrincipalName $_.UserPrincipalName -AddLicenses "package name”}

    Thanks,

    Neo Yu

     

    • Top 25 Contributor
    • Post Points: 0
  • The first cmd works after editing but the second one gives this error:

    PS C:\windows\system32> Get-MsolUser | Set-MsolUserLicense -UserPrincipalName $_

    .PN -AddLicenses "newlan:STANDARDWOFFPACKPACK_STUDENT"

    Set-MsolUserLicense : Cannot bind argument to parameter 'UserPrincipalName'

    because it is null.

    At line:1 char:55

    + Get-MsolUser | Set-MsolUserLicense -UserPrincipalName $_.PN -AddLicenses

    "newlan ...

    +                                                       ~~~~~

       + CategoryInfo          : InvalidData: (:) [Set-MsolUserLicense], Paramete

      rBindingValidationException

       + FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,M

      icrosoft.Online.Administration.Automation.SetUserLicense

    • Not Ranked
    • Post Points: 0
Page 1 of 2 (19 items) 1|2|