I want to use a csv to import multiple licences at once

Hello

I created a csv to create a user and add a licence at the same time with a csv.
Here is my csv:

UserPrincipalName,DisplayName,Password,UsageLocation,LicenseAssignment
Sandrine@emic.be,Sanne,Voka545464,be, …

When i run this with one LicenseSkuID it works perfect. But I am trying to figuring out how to do it when I need to assign multipile licences to a user.

I tried to put an array in my csv but that did not work.

This is my command:
“”"
$addpath = “C:\Users\rens.sergier\Desktop\addusers.csv”
import-csv addpath | foreach { New-Msoluser -UserPrincipalName .UserPrincipalName -Displayname _.displayname -Password .Password -UsageLocation _.UsageLocation -LicenseAssignment _.LicenseAssignment -ForceChangePassword $false}
“”"

Is this possible or not. I did not find an answer on the internet.

Thank you for your help!

From the official online help: https://docs.microsoft.com/en-us/powershell/module/msonline/new-msoluser

“[-LicenseAssignment <String>]”

This means the “LicenseAssignment” parameter accepts multiple strings.

You will need to split the “LicenseAssignment” property. How is this property formatted in the csv file?

You can also try looping through a list of licenses instead of a list of users.

I have no experience with “New-Msoluser” but you may try adding the users first from the list of users and then assigning the licenses from a list of licenses.

Is there a cmdlet that assigns the license without creating the user?

@ferc

Set-MsolUserLicense (MSOnline) | Microsoft Docs

When you import from a CSV, everything is a string, it contains no data types (e.g. dates, currency, etc.). You will need to convert it to an array:

PS C:\Users\rasim> $csv = @"
User,License
Frank,MsLicense1
Susie,MsLicense1;MsLicense2
"@ | ConvertFrom-Csv

$csv[1].License.GetType()

IsPublic IsSerial Name                                     BaseType
-------- -------- ----                                     --------
True     True     String                                   System.Object

PS C:\Users\rasim> $myCsvData = $csv | Select User, @{Name="License";Expression={$_.License -split ';'}}

PS C:\Users\rasim> $myCsvData[1].License.GetType()

IsPublic IsSerial Name                                     BaseType    
-------- -------- ----                                     --------    
True     True     Object[]                                 System.Array
1 Like

Thank for your hulp!
I tried some things and I find a solution that works perfect in my scenario:

#EERST DIT DEEL RUNNEN.
#Connecteren, path definiëren naar uw csv en AccountSku opvragen
$cred = Get-Credential
Connect-MsolService -Credential $cred
Connect-ExchangeOnline -Credential $cred
$addpath = "C:\Users\rens.sergier\Desktop\Powershell Scripts\addusers.csv"
$Tenant = Get-MsolCompanyInformation | Select Displayname | foreach {$_.Displayname}
Get-MsolAccountSku

#ACHTER RUN DEEL 1, MOETEN WE DIT DEEL RUNNEN!
#CSV importeren en de user aanmaken + koppelen licentie
#Ook in uw CSV altijd de licentienamen in quotes plaatsen!!!
import-csv $addpath | foreach { 
    if($_.License2 -ne $null) {
        New-Msoluser -UserPrincipalName $_.UserPrincipalName -Displayname $_.DisplayName -Password $_.Password `
        -LicenseAssignment $_.License1,$_.License2 -UsageLocation "BE" -ForceChangePassword $false
    }else {
        New-Msoluser -UserPrincipalName $_.UserPrincipalName -Displayname $_.DisplayName -Password $_.Password `
        -LicenseAssignment $_.License1 -UsageLocation "BE" -ForceChangePassword $false
          }
}

#Displayname veranderen met het bedrijf erachter
import-csv $addpath | foreach { 
$UPN = Get-MsolUser -UserPrincipalName $_.UserPrincipalName | Select UserPrincipalName | foreach {$_.UserPrincipalname} 
$OldDisplayName = Get-MsolUser -UserPrincipalName $_.UserPrincipalName | Select DisplayName | foreach {$_.Displayname} 
Set-MsolUser -UserPrincipalName $UPN -DisplayName ($OldDisplayName + " | " + $Tenant)
}