Use PowerShell to manage Exchange Online

Its Master's Voice

Visual Studio Code

Visual Studio Code (VS Code) is not only a development environment but allows the use of shells such as PowerShell, the command line, and Linux Bash. This approach has several advantages: You can use multiple shells in a single window and thus manage Exchange Online with PowerShell, as well as Linux shells, and manage other services on the network in parallel with PowerShell.

VS Code [3] is available free of charge as open source software. The major platforms – Linux, macOS, and Windows – are supported. The source code editor is mainly used for developing web applications but can also be used for management tasks. Combined, VS Code and PowerShell Core give you a powerful administration tool for use across different operating systems, especially if you also work with cloud environments like Exchange Online. You can even author scripts and combine them with other programming languages.

Integrating VS Code into Windows is easy. Versions for Windows, Linux, and macOS are available on the VS Code page I referred to before [3]. The installation takes just a few seconds. After launching, VS Code is ready for use. In the Terminal menu option you can open the shells currently supported, including PowerShell and PowerShell Core. You also can start and use several sessions in parallel, switching between the different terminals in the window, which makes it easier to develop scripts. To create new terminals, simply click on the plus sign. Moreover, the various icons let you display several sessions next to each other. In command code, you run VS Code from within a PowerShell session. The ise command opens PowerShell ISE from within a conventional session.

Extending VS Code

The Ctrl+P (Cmd+P on macOS) keyboard shortcut displays a search bar at the top. From here, you can install extensions for VS Code (Figure 1). For example, to install PowerShell, enter:

ext install powershell
Figure 1: VS Code can be extended, for example, to provide improved support for PowerShell.

When you click on an extension, its details appear on the right, and the extension is installed.

In VS Code you can specify which version of PowerShell you want to use. The settings can be found under File | Preferences | Settings (Code | Preferences | Settings on Macs) | Features | Terminals , where you decide which shell to use by default in Windows. If you store the PowerShell Core executable in C:\Program Files\PowerShell\6\ pwsh.exe, a PowerShell Core session will launch automatically. You can also open a terminal window with PowerShell by pressing the PowerShell button on the left.

The advantage of VS Code is that more than one shell can be used as a terminal. Extensions are also available, with which several shells can be integrated. One well-known example is the Shell Launcher extension, which you install in the same way as PowerShell support. More information is available from the Microsoft Shell Launcher page [4].

Once connected to Exchange Online, you can use virtually the same cmdlets that are available in the Exchange Management Shell.

Managing Exchange Online with PowerShell

Entering Get-Command displays a list of all commands available in PowerShell. The Exchange Management Shell additionally offers a comprehensive help feature. If you can only recall part of a command, the * wildcard is a big help. For example, typing

Get-Command *mailbox

displays all cmdlets with mailbox at the end of their names. If the command you are looking for is not included, you can even use multiple placeholders (e.g., Get-Command *mailbox*, which displays all commands in which the word mailbox occurs somewhere).

Once you find the cmdlet you want, PowerShell gives you more options. Almost all cmdlets occur as one of four types:

  • The New- prefix creates something (e.g., New-Mailbox).
  • The Remove- prefix deletes something (e.g., Remove-Mailbox).
  • The Set- prefix modifies something (e.g., Set-Mailbox).
  • The Get- prefix retrieves information about an object (e.g., Get-Mailbox).

Of course, many other cmdlets are available in addition to these cmdlets, such as Start, Stop, Export, and Import. However, most management tasks are covered by the New, Remove, Set, and Get cmdlets. If you type only the command, either nothing happens at all, the cmdlet displays all of the objects in the organization, or it prompts you for the identity of the object. For example, the Get-Mailbox cmdlet lists all the mailboxes in the organization. If you only want to edit a single object, you need to specify the name of the object. If you fail to do this, you either see an error message telling you which options are missing, which can be helpful, or the Exchange Management Shell gradually prompts you for the required options and creates the object (e.g., for New-Mailbox).

The same applies to the other Set, Remove, and Get cmdlets. However, if you prefer to type all the necessary information and options at the command line rather than typing them in one at a time when prompted, the Exchange Management Shell provides detailed help:

Help <cmdlet>
Help <cmdlet> -Detailed
Help <cmdlet> -Examples

The first cmdlet gives information about a cmdlet, and the second option gives more detailed information. The third options provides examples of a command. These Help cmdlets work for all commands in the Exchange Management Shell.

To get information about objects, use Get-Cmdlets. This information is far more complete in Exchange Management Shell than in Exchange Admin Center. With the |fl option, you can format the output. Again, you can see how much information Exchange Management Shell provides. If you do not want to display all information but only individual parameters, you can arrange them after the |fl option. To display only the display name, database, alias, and organizational unit (OU) for the mailbox , use the command (cmdlets are not case sensitive):

Get-Mailbox |fl DisplayName, Database, Alias, OrganizationalUnit

Instead of a formatted list (fl), you could go for a formatted table (ft).

Another option offered by Exchange Management Shell is to read the mailboxes within a mailbox store database. When you enter the Get-Mailbox command to get a list of all mailboxes in the organization, you also see the server on which the individual mailbox is located and whether a limit has been entered that prohibits sending. The command

Get-Mailbox | Format-Table DisplayName, Database

lets you display mailboxes sorted by the mailbox database and display name.

Buy this article as PDF

Express-Checkout as PDF
Price $2.95
(incl. VAT)

Buy ADMIN Magazine

Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content

comments powered by Disqus
Subscribe to our ADMIN Newsletters
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs

Support Our Work

ADMIN content is made possible with support from readers like you. Please consider contributing when you've found an article to be beneficial.

Learn More”>


		<div class=