Microsoft Power Apps, SharePoint, & Microsoft 365 Consulting Company

What is PowerShell for Office 365 and Why Should I be Using it?

You might’ve heard the term “shell” used in computer science before—essentially, a shell gives you access to services in an operating system, and can be either command-based, or have a graphical user interface.

Windows PowerShell has been around for a while (since 2006, in fact,) and Microsoft initially developed it for task automation and configuration management purposes. It has since become an open-source project that can be installed on Windows, macOS, and Linux. It’s based on the .NET framework, and includes both a command-line shell and a scripting language.

What is Office 365 PowerShell?

Office 365 PowerShell is a set of modules for Windows PowerShell that complements your Office 365 Admin center. With the admin center, you can manage all your Office 365 server products—but you can also do so with Office 365 PowerShell commands, which can be used for speed, automation, and other capabilities.

PowerShell also lets you see information you don’t have access to through the Admin Center alone. Similarly, some features are only configurable through PowerShell.

We should note that Office 365 PowerShell does not replace the Admin Center—rather, it’s designed to enhance it. So let’s take a better look at what’s available with PowerShell.

Office 365 PowerShell Can Reveal More Information

Although the Admin Center shows a lot of information, it doesn’t show all. More often than not, it actually shows more info than what you need at a time. But in the case you actually need more, PowerShell is the way to go.

Imagine, for instance, you want to see which users are in a given location because you have clients in both the US and Europe. You can do it in the Admin Center through a series of steps (going to the user’s properties, clicking details, then additional details, then scrolling to “Country or Region” then write down the user separately, and repeat for every user.) Or, provided you have the Windows Azure Active Directory module installed, you can use a simple command in PowerShell:

Get-MsoIUser will get you every Office Subscriotion user, but will only display their name and location due to the Select DisplayName, UsageLocation parameters. The command can obviously be refined for whatever you need. You can, for instance, add sorting:

Or filter by location (UK users in this case):

There are, of course, many more commands you can use. Be sure to check out Microsoft’s Office 365 PowerShell page for a full list!

Office 365 features that you can only configure with Office 365 PowerShell

Again, the admin center already gives you access to the most common and important administrative tasks. And it’s exactly because of that everything is not included, and for certain tasks, you need to use PowerShell.

For instance, if you want to create Skype for Business invitations: you can do it through the Admin Center:

However, suppose you want to disable to default settings regarding automatic entrance for anonymous users, enabling recording, or want all users to be designed as presenters. That’s where PowerShell comes in, provided you have the Skype for Business PowerShell module installed. This command will disable all those three default settings:

Where Set-CsMeetingConfiguration selects the settings for new Skype for Business online meetings, and AdmitAnonymousUsersByDefault $False disables anonymous users from joining, and so on for Conference Recording, and designating all users as presenters.

Bulk Operations

Visual Interfaces are typically designed with the purpose of performing one single operation at a time. Bulk operations, however, will take a long time in the Admin Center, and if you have to change a lot of things, or select a few things from within a large set, the Admin Center is very time-consuming.

So, for bulk operations, it’s much more efficient to use PowerShell. For instance, if you need to remove one single user from your SharePoint online sites: with the Admin Center, you’d have to go through a series of clicks and properties until you could remove the user’s permissions.

With PowerShell, if you wanted to remove Jerry Smith from all your sites, all you’d have to do is install the Connect to SharePoint Online PowerShell module, and run the following command:

Where Get-SPOSite finds all the SharePoint sites in your subscription, and for each one, removes the user Jerry Smith. This will also remove the user from the sites they don’t have access too, which is bound to incur in errors. But worry not! Just add -Group “Members” after the user, and it’ll target only sites they’re a member of!

This command might take a few minutes depending on the sites you have, but it’s still preferable to the hours you’d spend in the Admin Center doing it manually.

Data Filtering

As with the examples above, the Admin Center has the basics of what you need for data filtering. You can do a lot with Exchange’s filters, but for more refined searches, you’ll need to turn to PowerShell commands once more.

Say you’d want to find the mailboxes for users who live in New York or Boston. This command will do it for you:

Or for users who live anywhere, except for New York:

You can even filter for users whose last name ends in, for instance, “son” (like Johnson, Anderson, Thompson, and so on.)

Printing and Saving Data

With the Admin Center, you can see lists of data. Take this example of users who’re enabled for Skype for Business Online:

If you wanted to give that list to someone else, you’d have to save it to a file, and copy it onto another document. Not just that, the Admin Center doesn’t have a way to directly print the list.

So PowerShell comes to rescue once again. It can save and print lists, as well as exporting them straight to Excel.

And you’ll end up with a .CSV file in C:\Logs called “SfBUsers” that lists all users who can access Skype for Business Online. If you want an XML or HTML file instead of a CSV, just change them in the command and you’re set.

If you’d rather print the file directly, then this command would do it:

Cross-Management Across Products

Office 365 has various components that are designed to work together. When you add a new Office 365 User, there’s certain information (like their department and name) that will be available across all server products.

Product-specific information, however, is not available across the Office suite. If you wanted a report that shows if a user’s display name, as well as if they’re licensed for Office 365, while also showing if they’re enabled for Skype for Business Online and if their Exchange Mailbox is enabled—you couldn’t do it in the Admin Center. But you can with PowerShell.

Closing Thoughts

Long story short: PowerShell for Office is a powerful complement to the Admin Center, and if you find yourself doing a lot of repetitive tasks, then you should absolutely be using it, as it makes life much easier.

eSoftware Associates, Inc. is a premier Microsoft consulting firm focusing on

SharePoint, Office 365,Excel, Power Bi and Azure solutions.

If you’d like to schedule a free consultation please click here.