How to create an Office 365 user using PowerShell

How to create an Office 365 user using PowerShell

 

In this blog post, I’ll show you How to create an Office 365 user using PowerShell module also known as Microsoft Azure Active Directory PowerShell Version 2 Module.

The Microsoft Office 365 PowerShell module was first released 6 years ago with the transition of Microsoft BPOS to Office 365 brand change and was used with the *-MSOline* syntax.

Mid last year the version 2 of the module was released as beta and rebranded \ put under the Microsoft Azure Active Directory umbrella with the name Microsoft Azure Active Directory PowerShell Module.

It Is also Important to note that Office 365 Objects are actually Azure Active Directory objects and doesn’t sit Inside the Office 365 family brands logically and technically.

Before you To Install the module please visit the article How To Manage Office 365 Using PowerShell.

If just want to Install the new module use a PowerShell 5 or above console to Install the module using:

Install-module azuread
 

The prerequisites for this article are:

  • PowerShell 5.0 Installed on the machine
  • Admin permissions to Office 365

Once the module Is Installed and loaded open a PowerShell Console and type the cmdlets below to connect to Azure AD:

Note: As you can see, The Office 365 name \ brand Is not mentioned at all.

Import-module azuread
 
Connect-azuread
 
How to create an Office 365 user using PowerShell
How to create an Office 365 user using PowerShell

When connected, You will see the Tenant ID Information on the screen

How to create an Office 365 user using PowerShell
How to create an Office 365 user using PowerShell

Next, I’ll set the password policy parameters using the 3 line below.

Note: the last line will set the Password for the user.

$Password = "" | Select-Object password,forceChangePasswordNextLogin

$Password.forceChangePasswordNextLogin

$Password.password = "some password"

Once the Password Policy Is set, I’ll use the code below to create my Office 365 User.

New-AzureADUser -DisplayName "Tom Azure" -PasswordProfile $password -AccountEnabled $true -MailNickName "tom" -UserPrincipalName "[email protected]"
 

The above code can easily expend and used to create multiple users




Search blogs




Bitnami