Our Story

Who we are and how we solve complex IT challenges.

Our Certifications

Microsoft certifications and partnerships validating our technical expertise.

Leadership

Meet the Experienced Leadership Team Driving WME’s Success

Advisory Updates

Expert guidance on Microsoft, security, and compliance developments.

Case Studies

Real-world outcomes from complex Microsoft-focused IT engagements.

Podcast

Podcasts, panels, and interviews where WME leaders share how they help high-growth companies and IT partners scale.

Ebooks

Practical guides on the Microsoft moves you can’t afford to get wrong.

Financial Industry

Secure technology solutions for regulated banks and financial institutions.

Healthcare

Secure Microsoft solutions for compliant, connected, and modern healthcare organizations.

Manufacturing

Cloud and security solutions supporting modern manufacturing operations.

Non-Profit

Cost-efficient Microsoft solutions for mission-driven organizations.

Public Sector

Microsoft-based IT services for secure public sector modernization.

High Tech

Scalable cloud, security, and staffing for fast-growing technology companies.

SMBs

Scalable cloud, security, and staffing for fast-growing technology companies.

Cloud Migration Services

Transition your workloads to the cloud securely for greater scalability and performance.

Data Migration Services

Securely transfer your business data with minimal downtime and maximum integrity.

Application Migration Services

Move your applications seamlessly to modern platforms with minimal business disruption.

Identity & Security Migration Services

Strengthen identity management and security while transitioning to modern Microsoft solutions.

Security Solutions

Protect your business with proactive cybersecurity, compliance, and risk management solutions.

Endpoint Management

Secure, manage, and monitor every device with modern endpoint management solutions.

Licensing Optimization

Get discounted pricing, a dedicated licensing team, and a plan that fits how many seats you actually use.

Power Platform

Unlock the full potential of the Microsoft Power Platform Suite to streamline operations, automate repetitive tasks, and gain real-time insights that drive business growth.

Sharepoint Solutions

Supercharge your business productivity and enhance visibility through our proven SharePoint expertise.

IT Staffing

Connect with skilled IT professionals to strengthen your team and accelerate project delivery.

Accounting & Finance

Connect with experienced accounting and finance professionals to support your business goals.

Create Exchange 2013 Mailboxes in Bulk

September 26, 2014

The post will provide a script that will create Exchange 2013 mailboxes in bulk by either supplying a file of usernames, or usernames on the command line. This script will only work with Exchange 2013. You must either run this script directly on the Exchange server, or have PowerShell remote session rules enabled. You also have to have the ability to create mailboxes on the server.

When you first copy or download the script, be sure to input the name of your exchange server on line 32. This must be the “real” DNS name; a CNAME will not work. Be sure to leave the quotes around the name.

Next, be sure to change the AD search base on line 51. Again, make sure that you keep the quotes. If you do not want to limit your search, you can remove ‘-searchbase “ou=employees,dc=contoso,dc=com”‘ from the line. Keep in mind that the more records you bring in, the longer the script will take to execute.

Script Actions

The script does three things. The first thing it does is take the usernames from either the file or the command line and check them against Active Directory to ensure that they exist. If they do not, the script essentially throws them out to another variable and does not try to enable the mailbox. This variable is displayed later, so that you can see which ones do not exist. You can use this information to confirm the names to ensure that no mistake has been made.

Secondly, the script checks to ensure that the validated usernames do not already have a mailbox. Just as in step one, if the mailbox already exists, it throws those usernames out to another variable and does not try to enable them again. This variable is again displayed later so that you know exactly what happens.

Third, if the username is valid and the mailbox does not exist, the script enables the mailbox. You will again get a list of those users that were actually enabled.

Because of the active directory and mailbox checks, the script takes anywhere from 20 to 30 seconds to execute.

Executing the Script

There are two available parameters for you to specify: file and usernames. There is also a help section that can be viewed by typing “get-help .\enable-exchange-mailboxes”. Here is how we add one or multiple users by typing them from the PowerShell shell:

Notice that for one user, the parameter is still “usernames” and that if specifying multiple users, separate them with a comma.

If you want to use a file, specify it like this:

This file can contain as many usernames as you wish. You can only specify one file at a time.

I hope this script can improve your Exchange environment management. Here’s the entire script:

################################################

###                                         ###

###     Builds Exchange mailboxes           ###

###                                         ###

###    Change variable $exchange_ser to     ###

###    match name of your Exchange server   ###

###                                         ###

###    Change AD search base in line 51     ###

###                                         ###

################################################

# help section

<#

.SYNOPSIS

Enable mailboxes using username(s) or a file of usernames.

.PARAMETER File

Reference a file of usernames to enable.

.PARAMETER usernames

Reference one or more usernames to add.

.EXAMPLE

.\enable-mailbox.ps1 -usernames “username1,username2”

.EXAMPLE

.\enable-mailbox.ps1 -file “C:\usernames.txt”

#>

# define parameters

PARAM (

[string]$file,

[string]$usernames

)

$exchange_ser = “<server name>”

# take input from parameters and format it

$enable_mailboxes = @()

If ($file -ne “”) { $enable_mailboxes = get-content $file }

If ($usernames -ne “”) { $enable_mailboxes = $usernames.split(“,”) }

If (($file -eq “”) -and ($usernames -eq “”)) {

write-host “”

write-host “No parameters specified.” -ForegroundColor Red

write-host ‘Use “-file <path to file>” or “-usernames <usernames sperated by commas>”‘ -ForegroundColor Red

write-host “”

break }

write-host “” # line break

write-host “Validating User Accounts…” -ForegroundColor Green

# active directory check for user accounts

import-module activedirectory

$all_users = @()

$all_users += (get-aduser -filter * -searchbase “ou=employees,dc=contoso,dc=com” -ResultSetSize $null).SamAccountName

$f_enable_mailboxes = @()

$no_useracc = @()

ForEach ($enable_mailbox in $enable_mailboxes) {

If (($all_users -contains $enable_mailbox) -eq $true) { $f_enable_mailboxes += $enable_mailbox }

Else { $no_useracc += $enable_mailbox }

}

write-host “”

write-host “Enabling Mailboxes…” -ForegroundColor Green

# create powershell session to exchange server

$ps_session = new-pssession -ConfigurationName Microsoft.Exchange -ConnectionUri https://$exchange_ser/powershell

$a = Import-PSSession -session $ps_session -DisableNameChecking

# get current mailboxes

$cur_mailboxes = (get-mailbox -resultsize unlimited).Name

$exists = @()

$created = @()

# creates mailbox if it does not already exist

ForEach ($f_enable_mailbox in $f_enable_mailboxes) {

If (($cur_mailboxes -contains $f_enable_mailbox) -eq $true) { $exists += $f_enable_mailbox }

Else { enable-mailbox $f_enable_mailbox }

}

write-host “”

# display results

write-host “Already Existed:” -ForegroundColor Red

ForEach ($name in $exists) { write-host $name -ForegroundColor Red}

write-host “”

write-host “No User Account Found:” -ForegroundColor Red

ForEach ($name in $no_useracc) { write-host $name -ForegroundColor Red }

# remove PowerShell session

remove-pssession $ps_session

Disclaimer

All content provided on this blog is for information purposes only. Windows Management Experts, Inc makes no representation as to accuracy or completeness of any information on this site. Windows Management Experts, Inc will not be liable for any errors or omission in this information nor for the availability of this information. It is highly recommended that you consult one of our technical consultants, should you need any further assistant.

Share:

Facebook
Twitter
LinkedIn

Get Microsoft Updates Before They Cost You Downtime

Retirement dates, licensing changes, and security updates from a Microsoft-exclusive team, sent when they matter, not on a filler schedule.

More Posts

Case Study: Sharepoint Migration with Metadata Tagging

CLIENT TYPE Nonprofit / Community Organization BUSINESS PROBLEM The organization needed to migrate SharePoint content while improving document organization and searchability. SOLUTION DELIVERED WME migrated ...
Read Full Article

Case Study: Microsoft 365 Email Security Modernization

CLIENT TYPE Healthcare / Mental Health Services Organization BUSINESS PROBLEM A legacy email security platform was no longer sufficient for modern compliance, encryption, and threat ...
Read Full Article

Case Study: Device Migration Support During Tenant Transition

CLIENT TYPE Cybersecurity Organization BUSINESS PROBLEM A large-scale device migration during a tenant transition caused frequent technical issues, user disruption, and internal support bottlenecks. SOLUTION ...
Read Full Article

Get Microsoft Updates Before They Cost You Downtime

Retirement dates, licensing changes, and security updates from a Microsoft-exclusive team, sent when they matter, not on a filler schedule.
Subscription Form email