Exchange

Office 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 Office 365

Our starting point is to establish a connection to the Office 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 https://outlook.office365.com/powershell-liveid/ -Credential (Get-Credential) -Authentication Basic -AllowRedirection


Import-PSSession $Session -DisableNameChecking

1.PNG

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


Get-Mailbox

1.PNG

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 tom.huber@sid-500.at -Password (ConvertTo-SecureString -String 'Pa$$w0rd' -AsPlainText -Force) -ResetPasswordOnNextLogon $true

1.PNG

To check if this has worked, run


Get-Mailbox Tomh | Format-Table -AutoSize

1.PNG

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.

1.PNG

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

Unbenannt.PNG

5 replies »

  1. Sorry didnt get chance to complete my question, we have a Hybrid O365 enviornment when we create a new user we’re forced to do mailbox creation on-premise exchange 2010 (we have Azure AD premium with pwd write back enabled), or else we get user not getting created properly in on-premise AD. Would your method above work for us? THanks!

    Like

  2. Hi Patrick, thanks for all your work. I wanted to know if the O365 solution for creating new users will work in a hybrid environment

    Like

Leave a Reply

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

WordPress.com Logo

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

Google photo

You are commenting using your Google 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.