4 min read
How to Leverage IT Automation for Maximum Efficiency
Are you ready for a transformation of your IT operations? Our brand-new white paper, Maximizing IT Automation: The...
ScriptRunner Blog
The new set of cmdlets in the Exchange Online V2 Module proves to be a boon and somewhat of a bane for those engineers that move mailboxes to Exchange Online or manage Exchange Online in general.
They are a boon because the nine new cmdlets are simply more robust and faster than their predecessors. They are also a bane because they will require script re-coding as well as learning the new methodologies (PropertySets and Properties) that are now present in these cmdlets.
Overall Microsoft has sought to balance use, speed and compatibility with the previous PowerShell module for Exchange Online.
In order to use the new Exchange Online V2 Module, we need to make sure that we meet certain prerequisites. Let’s dive into that first.
Prerequisites
Let’s break down the installation for each of these components.
A basic install would look something like this:
Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force -Confirm:$False
If we wanted to verify NuGet needs to be installed, we can also verify the version installed or if any version is installed, like so:
$PackageProviders = (Get-PackageProvider -ListAvailable).Name
If ($PackageProviders -NotContains 'NuGet') {write-host 'NuGet is missing.'}
Now if NuGet is missing, then we run the installation code above, if however, NuGet is installed, we can force an installation of the correct, minimum version using the previous cmdlet either way.
More Information on NuGet.
Notice that the build numbers go all the way up to 2.12.1, but we only need to have 2.8.3 or higher.
In the case of the Microsoft Exchange Online PowerShell V2 Module, we need access to this repository in order to download the module. By default, this repository may not be trusted and as such we will need to make sure that it is. First, let’s verify if it is or not trusted from our workstation:
(Get-PSRepository -Name "PSGallery").InstallationPolicy
Set-PSRepository -Name "PSGallery" -InstallationPolicy Trusted
Then we can verify the change: (Get-PSRepository -Name "PSGallery").InstallationPolicy
Tip: Always verify the change to prevent any future errors, especially with dependent processes.
PackageManagement
For PackageManagement we need to make sure that we have at least version 1.4.5. Let’s check this with PowerShell:
Get-Package PackageManagement -MinimumVersion 1.4.5
If PackageManagement is not installed, we will get an error like this:
In order to install PackageManagement properly, we may need to perform some gymnastics. That is because there are dependencies that can cause the upgrade process to hiccup. However, if all goes well, this is the only line we need to install PackageManagement:
Install-Module PackageManagement -Force -SkipPublisherCheck
Then when we verify the installation we see this:
Notice that the “Source” for this package is the PowerShell Gallery which we allowed earlier.
PowerShell Get
In addition to the previous package management software, we also have a module that will allow Admins to discover, install and update PowerShell modules, DSC resources, scripts and more. This is the last prerequisite for installing the EXO V2 module.
How do we install it? First, do we have it installed? We only need version 2 or higher, so we will check to see if we have a module installed whose Major version is 2:
[int32]((Get-Module PowerShellGet).Version).Major
Now, let’s upgrade this to at least 2.0:
Install-module PowerShellGet -MinimumVersion 2.0.0.0 -Force -Confirm:$False -SkipPublisherCheck
If all goes as planned, we can verify our new version and see this:
Wait. What? This should be two now. What happened? Is the package updated on our machine now?
Get-Package PowerShellGet
OK. So, we have the right version, why was 1 displayed in our check? That’s because the module that is loaded is the old one. Well, that is an easy fix:
We see now that 2.x of PowerShellGet is loaded and ready for us. Now onto downloading the module:
Install-Module ExchangeOnlineManagement
Verify it is installed: Get-InstalledModule ExchangeOnlineManagement
Note: Your version may vary by the time you read this as 2.0.4 is the current version as of the writing of this article. However, in the past year or so this version has changed multiple times, as this screenshot of the version history shows:
Connect-ExchangeOnline
We are prompted for MFA or at least Modern Auth like other modules for Office 365. Before connecting we see this informational blurb:The module provides replacements for nine cmdlets, but also continues to provide the other 700+ original cmdlets from the original Exchange Online module that we have used for many years.
When we review our loaded modules, we see the new one on the top of the list, but we also see the original cmdlets listed in the last module (figure 11).
These cmdlets were chosen for two reasons – most likely to be used, but also the most likely to be slow or fail due to the amount of data returned and the load put on Exchange Online servers.
When using these cmdlets, it is important to note that we do indeed need to be aware of syntax and proper usage of the new parameters in order to get the correct data in Exchange Online.
Get-Mailbox | Where {$_.IsResource -eq 'True'} | Ft Name, Alias, PrimarySMTPAddress, *quota
With the new cmdlets, we need to rely on either PropertySets like this:
Get-EXOMailbox -PropertySets Minimum, Resource, Quota | Where {$_.IsResource -eq 'True'} | ft
Get-EXOMailbox -Properties Name,Alias,PrimarySMTPAddress, IsResource, IssueWarningQuota,ProhibitSendQuota, ProhibitSendReceiveQuota | Where {$_.IsResource -eq 'True'} | ft
While this provides the same results, it is already becoming quite unwieldy. Thus, choosing between Properties and PropertySets should be based on how many attributes one would need to display.
How do we tell which parameters/properties are usable with a Property Set? It is not documented in Get-Help or in the online help of Microsoft Docs. Let’s take for example Get-EXOMailbox from the previous example. We can see the list of all Property Sets listed in Get-Help for the cmdlet:
If we were looking for all Quota attributes, we see that there is a Quota Property. Using this reveals a lot of properties for an account:
Get-EXOMailbox Ted -PropertySets Quota
Notice that there are some properties that are not Quota related but instead are identifiers for the mailbox – UserPrincipalName, PrimarySMTPAddress and Identity. What are the minimum reported properties? Let’s review the example below as the default (no specified PropertySets) is “Minimum”:
Get-EXOMailbox Ted
Related links
Nov 28, 2024 by Heiko Brenn
Are you ready for a transformation of your IT operations? Our brand-new white paper, Maximizing IT Automation: The...
Nov 21, 2024 by Guy Leech
Perhaps it is because I began my professional coding career writing device drivers for Unix systems in C, back in the...
Nov 20, 2024 by Damian Scoles
What is Microsoft Purview for you? Do you already master data governance with it? Learn how PowerShell simplifies...
Damian Scoles is a ten-time Microsoft MVP specializing in Exchange, Office 365 and PowerShell who has 25 years of IT industry experience. He is based in the Chicago area and started out managing Exchange 5.5 and Windows NT. Over the years he has worked with Office 365 since BPOS and his experience has grown to include Azure AD, Security and Compliance Admin Centers, and Exchange Online. His community outreach includes contributing to TechNet forums, creating PowerShell scripts that can be found on his blogs, writing in-depth PowerShell / Office365 / Exchange blog articles, tweeting, and creating PowerShell videos on YouTube. He has written five PowerShell books and is also actively working on the book "Microsoft 365 Security for IT Pros".