question

EavenHuang-0590 avatar image
0 Votes"
EavenHuang-0590 asked ·

Powershell to create AD user account and assign an Office 365 license with Exchange Online

Dear IT pros,

I'm looking for an automation way by using PowerShell to do this task in batch, the requirement would be -
Create AD user account and assign an Office 365 license in Exchange Online without manually creating them one-by-one via GUIs

Suppose we have over 100 new users (that maybe coming as guest for one month or two only), can we use PowerShell to run scripts and maybe read the attributes from a .csv?
Thanks very much in advance for any suggestions and opinion.


Best regards
Eaven

windows-server-powershelloffice-exchange-online-itpro
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

KyleXu-MSFT avatar image
0 Votes"
KyleXu-MSFT answered ·

@EavenHuang-0590

Step 1 : Prepare CSV file as picture below:
42472-qa-kyle-10-48-42.png

Step 2: Modify the script below:

 $Mailboxes  = import-csv c:/temp/users.csv #Location of CSV file
 $PassWord = "Password123" #Default password for new created users, they are forced to change their password the next time they sign in.
 $planName="domain:SPE_E3" #Plane name of your Office 365. "Get-MsolAccountSku"
    
 foreach($Mailbox in $Mailboxes){
     New-MsolUser -UserPrincipalName $Mailbox.PrimarySmtpAddress -DisplayName $Mailbox.DisplayName -UsageLocation us -Password $password -ForceChangePassword $true
     Set-MsolUserLicense -UserPrincipalName $Mailbox.PrimarySmtpAddress -AddLicenses $planName
 }

Step 3: Connect with the Microsoft Azure Active Directory Module for Windows PowerShell
Step 4: Run this script(The output is the result of creating users, and those users will be assigned license in the next step automatically):

42483-qa-kyle-10-57-49.png

You can use command below to double check the license status of new users:
42501-qa-kyle-10-59-20.png


If the response is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


· 1 · Share
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

@EavenHuang-0590
I am writing here to confirm with you any update about this thread now?
If the above suggestion helps, please be free to mark it as an answer for helping more people.

0 Votes 0 ·