Microsoft 365

Microsoft 365: Add User Accounts and Mailboxes with PowerShell

More and more companies are moving to the cloud. Subscribing cloud services means less hardware maintenance, more comfort, and an “always-on” feeling. As an administrator, you have to get familiar with the administration of cloud services, especially with the basics like creating user accounts and user mailboxes. In this article I will carry out adding user accounts along with adding user mailboxes with Powershell.

Connect to Microsoft 365

Our starting point is to establish a connection to the Microsoft 365 | Exchange Online portal. In order to do that we need two commands. I’ll do anything with PowerShell 7. Feel free to use Windows PowerShell 5.1.

$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri -Credential (Get-Credential) -Authentication Basic -AllowRedirection

Import-PSSession $Session -DisableNameChecking


Finally, check your connection by running Microsoft 365 commands like Get-Mailbox.



Adding new email-enabled Users

When a mailbox is created, a new user is also created at the same time. So, this is a one-stop shop.

The following example creates a user account and mailbox for the user Tom Huber. Tom must change the password at next logon.

New-Mailbox -Alias tomh -Name tomh -FirstName Tom -LastName Huber -DisplayName "Tom Huber" -MicrosoftOnlineServicesID -Password (ConvertTo-SecureString -String 'Pa$$w0rd' -AsPlainText -Force) -ResetPasswordOnNextLogon $true


To check if this has worked, run

Get-Mailbox Tomh | Format-Table -AutoSize


You can also take a look at your Office 365 portal.

The user must still be assigned a license. Assigning a license is out of scope of this blog post, but it’s worth to mention that you can do it right here.


See also

As mentioned before, you need to enter two commands to connect to the Office 365 portal. For your convenienve, I’ve created a Powershell function that connects you with a single command. For more, see Office 365 Exchange Online PowerShell: Quick connect with Connect-ExchangeOnline


15 replies »

  1. this didnt work for me.

    parameter cannot be found that matches parameter name ‘MicrosoftOnlineServicesID’.
    + CategoryInfo : InvalidArgument: (:) [New-Mailbox], ParameterBindingException
    + FullyQualifiedErrorId : NamedParameterNotFound,New-Mailbox
    + PSComputerName : ppgimsexmgt01.parentpay.local

    can anyone help?


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.