set mailbox powershell script

**"PowerShell Script: Set Mailbox in a Snap"**

By Mark Miller
AD

Are you looking to automate the process of managing mailboxes in your Exchange Server environment? PowerShell, with its extensive capabilities, is an excellent tool for this task. In this article, we'll guide you through creating a PowerShell script to set mailbox properties, focusing on Exchange Online and on-premises Exchange Server 2016/2019. Let's dive in!

Understanding the Set-Mailbox cmdlet

The Set-Mailbox cmdlet in PowerShell is your go-to command for modifying mailbox properties. It's versatile, allowing you to change various attributes such as display name, email addresses, mailbox quotas, and more. Before we start scripting, let's explore some key parameters:

  • Identity: Specifies the mailbox to modify. It can be a user, group, or contact.
  • DisplayName: Sets the display name of the mailbox.
  • EmailAddresses: Modifies the email addresses associated with the mailbox.
  • ForwardingSmtpAddress: Sets the email address where the mailbox's messages are forwarded.
  • MailboxQuota: Defines the mailbox size limit in bytes.

Setting up your PowerShell session

Before you start scripting, ensure you have the required PowerShell modules and permissions. For Exchange Online, use the Exchange Online PowerShell V2 module. For on-premises Exchange, ensure you have the Exchange Online PowerShell V2 module or the Exchange Server PowerShell module installed.

AD
Can't run PowerShell script in Windows 11
Can't run PowerShell script in Windows 11
20 Windows PowerShell Commands You Must Know
20 Windows PowerShell Commands You Must Know
PowerShell vs CMD: Key Differences, Uses & Beginner Guide
PowerShell vs CMD: Key Differences, Uses & Beginner Guide

To connect to Exchange Online, run:

```powershell Connect-ExchangeOnline -UserPrincipalName admin@example.com ```

For on-premises Exchange, use:

the powerball info sheet is shown in blue and white
the powerball info sheet is shown in blue and white
Windows IoT Core: Running a PowerShell Script on Startup
Windows IoT Core: Running a PowerShell Script on Startup
PowerShell Continue
PowerShell Continue
```powershell $UserCredential = Get-Credential $Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https:// /PowerShell/ -Credential $UserCredential -Authentication Basic -AllowRedirection Import-PSSession $Session ```

Creating the Set-Mailbox PowerShell script

Now that we're set up, let's create a script that sets mailbox properties based on a CSV file. The CSV should have columns for Identity, DisplayName, EmailAddresses, and any other properties you want to modify.

Example CSV format

``` Identity,DisplayName,EmailAddresses,ForwardingSmtpAddress,MailboxQuota user1@example.com,"User One","user1@example.com","user1-forward@example.com",10GB user2@example.com,"User Two","user2@example.com","","5GB" ```

PowerShell script

```powershell # Import the CSV file $mailboxes = Import-Csv -Path "C:\Path\to\mailboxes.csv" # Loop through each mailbox in the CSV foreach ($mailbox in $mailboxes) { # Set mailbox properties Set-Mailbox -Identity $mailbox.Identity -DisplayName $mailbox.DisplayName -EmailAddresses $mailbox.EmailAddresses # Set forwarding address if provided if ($mailbox.ForwardingSmtpAddress -ne "") { Set-Mailbox -Identity $mailbox.Identity -ForwardingSmtpAddress $mailbox.ForwardingSmtpAddress } # Set mailbox quota if provided if ($mailbox.MailboxQuota -ne "") { Set-Mailbox -Identity $mailbox.Identity -MailboxQuota $mailbox.MailboxQuota } Write-Host "Updated mailbox: $($mailbox.Identity)" } ```

Verifying the script's output

After running the script, you can verify the changes by using the Get-Mailbox cmdlet. For example:

```powershell Get-Mailbox -Identity user1@example.com | Format-List DisplayName,EmailAddresses,ForwardingSmtpAddress,MailboxQuota ```

This will display the updated properties for the specified mailbox.

Troubleshooting common issues

If you encounter errors while running the script, ensure you have the correct permissions and that the mailbox identities match the format expected by Exchange. You can also use the Try-Catch statement to handle errors gracefully and continue processing the remaining mailboxes.

That's it! You now have a powerful PowerShell script to set mailbox properties in your Exchange environment. Happy automating!

Smart Mailbox
Smart Mailbox
The Ultimate PowerShell Commands Cheat Sheet | NinjaOne
The Ultimate PowerShell Commands Cheat Sheet | NinjaOne
the mail merge button in microsoft's office 365 email address box is highlighted on the left side of the document
the mail merge button in microsoft's office 365 email address box is highlighted on the left side of the document
One PowerShell Command Completely Rebuilds Windows 11 Start Menu (When Nothing Else Works)
One PowerShell Command Completely Rebuilds Windows 11 Start Menu (When Nothing Else Works)
the virtual machine dialogg screen shows that it is time to set up an application
the virtual machine dialogg screen shows that it is time to set up an application
Building Eclipse Projects with custom external Shell Scripts
Building Eclipse Projects with custom external Shell Scripts
PowerShell for beginners: Scripts and loops
PowerShell for beginners: Scripts and loops
the blue screen in windows 10
the blue screen in windows 10
What is PowerShell and how do you use it?
What is PowerShell and how do you use it?
Here's How to Add A Shared Mailbox into Outlook
Here's How to Add A Shared Mailbox into Outlook
6 Basic PowerShell Commands to Get More out of Windows
6 Basic PowerShell Commands to Get More out of Windows
What is AutoArchive in Outlook and How Does it Work?
What is AutoArchive in Outlook and How Does it Work?
How to Set Up an 'All Mail' Folder in Outlook
How to Set Up an 'All Mail' Folder in Outlook
How to Manage Windows Firewall Rules with PowerShell
How to Manage Windows Firewall Rules with PowerShell
Stellar Converter for OLM: How to Convert Mac Outlook (OLM) to PST - SmashingApps.com
Stellar Converter for OLM: How to Convert Mac Outlook (OLM) to PST - SmashingApps.com
How to transfer OneDrive files to another user via PowerShell
How to transfer OneDrive files to another user via PowerShell
9 Ways to Open the Command Prompt or PowerShell on Windows
9 Ways to Open the Command Prompt or PowerShell on Windows
What Is Windows PowerShell?
What Is Windows PowerShell?
How to customize the subject line in Mail Merge Toolkit for Outlook
How to customize the subject line in Mail Merge Toolkit for Outlook
How to Create, Manage & Change Inbox View in Outlook
How to Create, Manage & Change Inbox View in Outlook
AD