Many organizations have moved to the cloud, taking away most of the administration work you would have if you were running local Exchange Servers like Exchange 2016, Exchange 2019, or legacy Exchange like Exchange 2013, Exchange 2010, or even Exchange 2007. (Yes, there are companies still using Exchange 2007!) But the same limitation you have with on-premises Exchange Servers is also there with Microsoft Office 365. There is only so much you can do from the Microsoft 365 web interface — the rest you need to do from PowerShell 7.
Installing PowerShell 7
PowerShell 7, which has been out for a little over a year now, seems to be snappier and faster than the older versions. You obviously cannot run everything from PowerShell 7 — for example, Exchange on-premises cmdlets — but it is great to use Microsoft 365 commands. So how do you get PowerShell 7? If you have been playing around with PowerShell 7 since it was in Preview mode, you can upgrade to the latest version using the command line or open up your existing PowerShell 7 to this version or the latest version out. You can also download it using the same command to install. Here is the command:
iex “& { $(irm https://aka.ms/install-powershell.ps1) } -UseMSI”
Do not try to run this from a command prompt window, as you will receive an error that it does not know what “iex” is.
Open this up in a normal PowerShell window as shown below:
Once the file has downloaded (in this example it is Version 7.1.3 but my screenshots are 7.1.0), the same rule applies — you will be presented with the setup, and here are the steps for each screenshot which is pretty straightforward:
Click Next to continue.
Leave the default path to install PowerShell 7 or change it to where you want it to go, and then click Next.
Make your selection from the options above, and click Next.
Click the install button to start the installation of PowerShell 7.
The setup validates the install and then continues.
This is a progress screen.
Once the install is done, you can either select the box to Launch PowerShell or click Finish to complete your installation.
When you launch PowerShell 7, you will see a window similar to the above showing you the version. You will notice the difference between PowerShell 5 and 7 are the icons. Version 5 has a light icon and V7 has a dark PowerShell icon.
Running PowerShell 7 commands against your Microsoft 365 tenant
You can now proceed with the new version and run PowerShell commands against your Microsoft Office 365 tenant. If you need to import the SkypeOnlineConnector.psd1 module and receive an error, head over to the Microsoft site, download the latest version, and try again. It should succeed.
To connect to your tenant, you can now launch PowerShell 7 elevated and run the following commands:
Install-Module -Name MSOnline
Type in “Y” and then press enter and it will start installing the package as shown below:
Now we can move to the next command with is the AzureAD one. You can use the following command and then press enter:
Install-Module -Name AzureAD
You will receive the same kind of prompt as you did with the first command. Type “Y” and press enter:
This will download and install the packages like the previous one as shown below:
Once the install is complete, we are now ready to connect to our Microsoft Office 365 tenant. Take note that the Azure Active Directory module only works up to PowerShell Version 6.
In the same PowerShell window, you can type the command below:
Get-Credential
You will either get a box popup or it will be within the same window as shown below:
Enter in your details for your tenant and press enter, or you can use a variable like $cred = Get-Credential as we will use the variable in the next command. Once you have entered the details and pressed enter, you will be taken back to the command prompt as shown below:
If you try the MSolService, you will receive an error that the command is not recognized. This is because we need to run the command Import-Module MSOnline before you can connect to it.
Now you can run the Connect-MSolService command, and it should not give you an error.
Connecting to Exchange Online
We can connect to Exchange Online as well. You will need to install the “Install-Module -Name ExchangeOnlineManagement” module and then connect to it as shown below:
The same applies to Microsoft Teams — you need to first install the module and then you can import it. After that, you need to connect to it like the above commands. If you run a Get-Team, for example, it will list all the teams in your tenant.
Some modules work in compatibility mode and others work fine as is. With Exchange Online and AzureAD cmdlets updated continually, it will only be a matter of time when they don’t need to run in compatibility mode.
Featured image: Shutterstock / TechGenix photo illustration