Jan 27 2022 05:37 AM - edited Jan 27 2022 05:45 AM
Hi
I use a simple script (and it works) to bulk create new users on my M365 tenant (cloud based only).
I'm missing something here, because, I assumed that the UserPrincipalName also could be the new email address.
What do I need to in order to also create a valid email address as well?
Below is the online script, and the CSV file it references.
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"
Thanks.
Jan 27 2022 08:32 AM
Jan 27 2022 10:12 AM - edited Jan 27 2022 10:13 AM
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
Jan 27 2022 10:16 AM
Jan 28 2022 03:05 PM
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.NewUser
The domain has been accepted (see screendump).
It's really weird, and any help is welcome.
Thanks.
Jan 28 2022 04:28 PM
Solution@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 :p
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 29 2022 01:43 AM
Jan 29 2022 02:33 AM
Jan 28 2022 04:28 PM
Solution@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 :p
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"