PowerShell Gems That Every Microsoft 365 Administrator Should Know About

As an IT Professional, can you survive without PowerShell? I can imagine there are several debates around this topic on Reddit right now. The short answer is yes, you probably can (barely). However, keeping PowerShell as your go-to tool on your IT Pro toolbelt will bring you varying productivity and efficiency boosts. Quite simply, the more you use it, the more you will accomplish in a shorter amount of time. Your supervisor/manager will rarely, if ever, complain about you completing your Microsoft 365 Admin tasks earlier than promised or needed. Plus, your users and employees you support will always be grateful their support issue or service request is completed in a timely manner! I’ll explore the various Microsoft 365 online services and how PowerShell can help you get your job done.

Note – Wondering how to efficiently connect to all the core Microsoft 365 online environments with a single PowerShell script? Don’t worry, I’ve got an example script at the end of the article.

Let’s start with SharePoint Online (SPO). To create a new Site Collection, use the ‘NewSPOSite’ cmdlet:


This will create a new site with the above URL, the Primary Admin of the site collection being the ‘Owner’, setting the Quota for the site to about 1 GB, and giving it a Title.

If you want to add yourself or another admin on your team to a site as a Site Collection Admin, you can use the ‘Set-SPOUser’ cmdlet.


Let’s move on to Teams! Microsoft has been increasing the breadth of cmdlets for Teams since Day 1. Let’s start with creating a new Team; you’ll accomplish this with the ‘New-Team’ cmdlet:


Whoever creates the Team will automatically be made an Owner (admin) of the Team. Before we add an additional administrator as an ‘Owner’ of the team, we first need to identify the Microsoft 365 Group’s ‘GroupId’ by using the ‘Get-UnifiedGroup’ cmdlet. To avoid a potential human error with copying and pasting strings, let’s store the result in a string, ‘$GroupId’:


Or


The GroupId of the Microsoft 365 Group is stored in that string. To add an administrator as an Owner of our Team, we use the ‘Add-TeamUser‘ cmdlet:


The next service is Azure Active Directory (AAD). A recent service request I handled was to create a new Microsoft Plan for a user based on an existing Plan. That’s easy enough using the Planner website (Copy Plan). However, the user also wanted the 55 Members of the existing Plan (Microsoft 365 Group) added to the new Plan (Group). Well, you can understand how tedious and time-consuming (Oh No!) that would be adding those users one by one with a website Admin Center interface or even PowerShell one command at a time. Let’s use the scripting capabilities built into PowerShell to save the day!

First, let’s store the membership of the existing Microsoft 365 Group in a string called ‘$members’ using the ‘Get-UnifiedGroupLinks’ cmdlet:


In my scenario, those 55 members’ info is now stored in $members. Let’s go ahead and add them, ‘one-by-one’, using PowerShell scripting via the ‘Add-UnifiedGroupLinks’ cmdlet:


You can verify this magic worked by displaying the members of each group:



They should be the same.

Note – Only Members, not Admins, of the Groups, will be copied. Instead of ‘-LinkType Members’ use ‘-LinkType Admins’.

Here’s the Bonus PowerShell script I promised. This will connect you to the following services:

  • Azure Active Directory (AAD)
  • SharePoint Online (SPO)
  • Skype for Business Online (SfBO)
  • Exchange Online (EXO)
  • Teams


The only prerequisite implied here is that you have all the pertinent PowerShell modules installed before running the script.

Please feel free to leave any comments about the content and if you’re interested to see more in-depth coverage of specific Microsoft online services or even specific PS cmdlets!

Related Topics:

  • Microsoft 365
  • BECOME A PETRI MEMBER:

    Don't have a login but want to join the conversation? Sign up for a Petri Account

    Register

    More Articles by Michael Reinders