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 29, 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"
jensjakobsen1966
Jan 28, 2022Brass Contributor
I used the script:
Import-Csv -Path "C:\Users\Jens Jakobsen\users.csv" | ForEach {New-MsolUser -DisplayName $_.DisplayName -FirstName $_.FirstName -LastName $_.LastName -UserPrincipalName $_.UserPrincipalName -UsageLocation $_.UsageLocation -LicenseAssignment $_.AccountSkuId} | Export-Csv -Path "C:\Users\Jens Jakobsen\Results.csv"I received the error:
New-MsolUser : You must provide a required property: Parameter name: UserPrincipalName
At line:1 char:64
+ ... | ForEach {New-MsolUser -DisplayName $_.DisplayName -FirstName $_.Fi ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : OperationStopped: (:) [New-MsolUser], MicrosoftOnlineException
+ FullyQualifiedErrorId : Microsoft.Online.Administration.Automation.RequiredPropertyNotSetException,Microsoft.Online.Administration.Automation.NewUser
New-MsolUser : You must provide a required property: Parameter name: UserPrincipalName
At line:1 char:64
+ ... | ForEach {New-MsolUser -DisplayName $_.DisplayName -FirstName $_.Fi ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : OperationStopped: (:) [New-MsolUser], MicrosoftOnlineException
+ FullyQualifiedErrorId : Microsoft.Online.Administration.Automation.RequiredPropertyNotSetException,Microsoft.Online.Administration.Automation.NewUserThe domain has been accepted (see screendump).
It's really weird, and any help is welcome.
Thanks.
Jan 29, 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"
- jensjakobsen1966Jan 29, 2022Brass ContributorThanks, the change from semicolon to commas worked. Much appreciated - I felt blind at the end 🙂
- Jan 29, 2022No problem, didn't see it until I downloaded your sample file and didn't get the correct output from just doing a import-csv. Sometimes you have to chop the script into pieces and validate each one 😉