Coming Soon: GET:IT Endpoint Management 1-Day Conference on September 28th at 9:30 AM ET Coming Soon: GET:IT Endpoint Management 1-Day Conference on September 28th at 9:30 AM ET
Microsoft 365

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:

New-SPOSite -Url -Owner [email protected] -StorageQuota 1000 -Title "Welcome to PowerShell"

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.

Set-SPOUser -Site -LoginName [email protected] -IsSiteCollectionAdmin $true

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:
New-Team -Name "PowerShell Reference" -Description "Collaboration space to include PowerShell cmdlets for the Team”

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’:
$GroupId = Get-UnifiedGroup -identity [email protected] | fl ExternalDirectoryObjectId

$GroupId = Get-UnifiedGroup -identity “Title/Name of M365 Group” | fl ExternalDirectoryObjectId

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:
Add-TeamUser -GroupId $GroupId -User [email protected] -Role Owner

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!

Sponsored Content

Say Goodbye to Traditional PC Lifecycle Management

Traditional IT tools, including Microsoft SCCM, Ghost Solution Suite, and KACE, often require considerable custom configurations by T3 technicians (an expensive and often elusive IT resource) to enable management of a hybrid onsite + remote workforce. In many cases, even with the best resources, organizations are finding that these on-premise tools simply cannot support remote endpoints consistently and reliably due to infrastructure limitations.

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

$members = Get-UnifiedGroupLinks -identity ExistingGroupEmailAddress -LinkType Members

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:
foreach ($item in $members) {Add-UnifiedGroupLinks -identity NewGroupEmailAddress -LinkType Members -Links $item.primarysmtpaddress}

You can verify this magic worked by displaying the members of each group:
Get-UnifiedGroupLinks -identity ExistingGroupEmailAddress -LinkType Members

Get-UnifiedGroupLinks -identity NewGroupEmailAddress -LinkType Members

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

$acctName="[email protected]"
#Azure Active Directory
#SharePoint Online
Connect-SPOService -Url
#Skype for Business Online
$sfboSession = New-CsOnlineSession
Import-PSSession $sfboSession
#Exchange Online
Connect-ExchangeOnline -UserPrincipalName $acctName -ShowProgress $true
Import-Module MicrosoftTeams

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:


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

Comments (0)

Leave a Reply

Live Webinar: Active Directory Security: What Needs Immediate Priority!Live on Tuesday, October 12th at 1 PM ET

Attacks on Active Directory are at an all-time high. Companies that are not taking heed are being punished, both monetarily and with loss of production.

In this webinar, you will learn:

  • How to prioritize vulnerability management
  • What attackers are leveraging to breach organizations
  • Where Active Directory security needs immediate attention
  • Overall strategy to secure your environment and keep it secured

Sponsored by: