Forum Discussion
jensjakobsen1966
Jan 27, 2022Brass Contributor
Powershell bulk creation - error with UserPrincipalName
Hi I use a simple script (and it works) to bulk create new users on my M365 tenant (cloud based only). When I set the UserPrincipalName to e.g. [jan . jensen @ DOMAIN . onmicrosoft . com] it...
- Jan 28, 2022
jensjakobsen1966 The delimeter parameter was not specified and import-csv expects the comma and the delimeter is a semicolon in your sample file. Added the parameter and it should work now 😛
Import-Csv -Path "C:\Users\Jens Jakobsen\users.csv" -Delimeter ';' | ForEach {New-MsolUser -DisplayName $_.DisplayName -FirstName $_.FirstName -LastName $_.LastName -UserPrincipalName $_.UserPrincipalName -UsageLocation $_.UsageLocation -LicenseAssignment $_.AccountSkuId} | Export-Csv -Path "C:\Users\Jens Jakobsen\Results.csv"
Jan 27, 2022
What error do you receive when creating a test user manually?
New-MsolUser -DisplayName 'Harm Test' -FirstName Harm -LastName Test -UserPrincipalName Email address removed -UsageLocation NL
Because this should work if you have the domain added to your tenant of course 😉 (I just used the above syntax and my user is there)
New-MsolUser -DisplayName 'Harm Test' -FirstName Harm -LastName Test -UserPrincipalName Email address removed -UsageLocation NL
Because this should work if you have the domain added to your tenant of course 😉 (I just used the above syntax and my user is there)
jensjakobsen1966
Jan 27, 2022Brass Contributor
Hello Harm
The example email you used has been removed by the editor. You have to use the syntax, as I did in my first question.
I tried a one-liner, with no CSV file, and it worked like a charm. Below is the one-liner I used:
New-MsolUser -DisplayName "Lars Larsen" -FirstName Lars -LastName Larsen -UserPrincipalNamelars . larsen @ DOMAIN . dk -UsageLocation DK -LicenseAssignment kvikkastrup:STANDARDPACK