PowerShell is very powerful (no pun intended) but if you don’t know what you are doing it can be dangerous, making big changes to your environment without prompting for confirmation. If you run ANY PowerShell scripts against your Office 365 tenant you alone are fully responsible for the actions undertaken, so please ensure you are fully confident in the source of your information.
I would recommend having a look at the Microsoft Learn module as a first step. It should only take approx 1h to complete. Introduction to PowerShell – Learn | Microsoft Docs
Then review the guidance on managing Microsoft Teams using PowerShell from Microsoft Microsoft Teams PowerShell Overview – Microsoft Teams | Microsoft Docs
If you are looking at scripts for Microsoft Teams from a blog (like this one) I would recommend checking them against MicrosoftTeamsPowerShell Module | Microsoft Docs. This helps you learn more about the scripts but also lets you check the cmdlets (commands) you intend to use are still valid.
ALWAYS close your PowerShell Windows when you are not actively using them. This closes the connection and logs you out, helping to keep your environment secure. Or even better disconnect then close the window.
Finally remember that Teams runs on Microsoft 365 groups, includes SharePoint features and shares some configuration with Skype for Business Online. This means you may also need to use PowerShell cmdlets for Azure AD Power, Exchange Online, SharePoint and Skype for Business too, though the Skype for Business Online cmdlets are included in the Teams PowerShell module, they are still referenced separately in Docs.
This blog series is designed to support those studying for the MS-700 exam to appreciate how to do many of the tasks in the course using PowerShell. As such I have divided it down into the course modules, which also help other trainers when they are delivering.
In this blog I have used <aaa> to indicate where you should change parts of the script to apply to your requirements. Replace the <> as well as the words, but not any ” ” so <email> would become someone@email.com and “<email>” would become “someone@email.com”
REMEMBER: Any scripts here are run at your own risk, though I have tested them, I offer no guarantees or warrantees.
Overview
https://docs.microsoft.com/en-gb/microsoftteams/teams-powershell-overview
https://docs.microsoft.com/en-us/powershell/skype/intro?view=skype-ps
Install, Connect & Upgrade Teams PowerShell
- Open Powershell in Windows with Admin – right click on your start button and choose Windows PowerShell (Admin)
- Install Teams Powershell by running this script (see Install Microsoft Teams PowerShell – Microsoft Teams | Microsoft Docs)
Install-Module -Name MicrosoftTeams
- Import the newly installed module into the open PowerShell window
Import-Module MicrosoftTeams
- Log in to Microsoft Teams
Connect-MicrosoftTeams
- You are now ready to manage Teams using PowerShell
When you are installing PowerShell Modules, you will always be prompted to confirm download from the repository, as shown below. You should only confirm one repository at a time using Y response.

Once set up you can then log in future by:
- Open Powershell in Windows with Admin – right click on your start button and choose Windows PowerShell (Admin)
- Import the Teams module into the open PowerShell window
Import-Module MicrosoftTeams
- Log in to Microsoft Teams
Connect-MicrosoftTeams
To Update Teams Powershell
- Open Powershell in Windows with Admin – right click on your start button and choose Windows PowerShell (Admin)
- Run the Update Script
Update-Module MicrosoftTeams
- Import the Teams module into the open PowerShell window
Import-Module MicrosoftTeams
- Log in to Microsoft Teams
Connect-MicrosoftTeams
Learn more about the Teams PowerShell Module
The commands in this section are not needed for the MS-700, but they do help to understand the Teams PowerShell module.
List Available Versions of Teams PowerShell Module
Get-Module -Name MicrosoftTeams* -ListAvailable | select Name,Version,Path
What is included in the Teams PowerShell Module
These cmdlets will let you explore what is availalbe in the Microsoft Teams PowerShell module
List all cmdlets
Get-Command -CommandType Cmdlet -Module MicrosoftTeams
List all commands
Get-Command -Module MicrosoftTeams
List all commands which use ‘Get’
Get-Command -Module MicrosoftTeams -Verb Get
List all commands which use ‘set’
Get-Command -Module MicrosoftTeams -Verb Set
List all commands which use ‘New’
Get-Command -Module MicrosoftTeams -Verb New
List all commands which act on a ‘Team’
Get-Command -Module MicrosoftTeams -Noun Teams
List all commands which act on a ‘Channel’
Get-Command -Module MicrosoftTeams -Noun TeamChannel
How Many commands are included in the Teams PowerShell Module
Get-Command -Module MicrosoftTeams |Measure-Object
Get help about with the New-Team PowerShell cmdlet
Get-Help New-Team
You can replace the New-Team cmdlet in this script with any cmdlet. However this returns the help in the PowerShell window so you may prefer to open the help file in a separate window or even online using:
Get-Help New-Team -ShowWindow
Or
Get-Help New-Team -Online
Disconnect
You do not need to disconnect from Teams in PowerShell but it is a good idea to do so before closing your PowerShell window using:
Disconnect-MicrosoftTeams
Assign Teams Admin Role via PowerShell
You need to use the Azure AD PowerShell Module for this.
- Open Powershell in Windows with Admin – right click on your start button and choose Windows PowerShell (Admin)
- Install AzureAD Powershell by running this script (see Connect to Microsoft 365 with PowerShell – Microsoft 365 Enterprise | Microsoft Docs) You should also be prompted to confirm NuGet and PSGallery access during the install of this module
Install-Module MSOnline
- Log in to Azure AD
Connect-MsolService
- Check names of roles which can be assigned using
Get-MsolRole | Sort Name | Select Name,Description
The teams admin roles are:
- Teams Administrator
- Teams Communications Administrator
- Teams Communications Support Engineer
- Teams Communications Support Specialist
- Teams Devices Administrator
- Copy the script below and replace <email> with login email address of user to be assigned the role and <role> with the role to be assigned.
$upnName="<email>"
$roleName="<role>"
Add-MsolRoleMember -RoleMemberEmailAddress $upnName -RoleName $roleName
Finding out about your tenant
You can also find quite a lot of information about your Teams tenant using PowerShell. The cmdlets are all from the Teams module.
Get a list of all Teams in the tenant using:
Get-Team
Find What Details You Can Display About a Team using:
Get-Team |Get-Member
Get details of a Single Team using:
Get-Team -DisplayName <TeamName>
Get a list of all archived teams using:
Get-Team -Archived $true
Get List of all Team Users using:
Get-Team |Get-TeamUser
Get list of Unique Teams Users (each user listed once) using:
Get-Team |Get-TeamUser |Sort UserID -Unique
Get list of team members and role for one team using
$Team=Get-Team -DisplayName <TeamName>
Get-TeamUser -GroupID $Team.GroupID | Select User, Role
Get a list of all Guest users in all Teams using:
You will need all the lines below:
$Teams = Get-Team
foreach ($Team in $Teams) { Get-TeamUser -GroupId $Team.GroupID | where {$_.Role -eq "Guest"} | Select User, Role, @{n='TeamName' ;e={$Team.DisplayName}}}
For large environments, displaying the info in the PowerShell Window is messy, so create a csv export of owners and members of each Team using:
$AllTeams = (Get-Team).GroupID
$TeamList = @()
Foreach ($Team in $AllTeams)
{
$TeamGUID = $Team.ToString()
$TeamName = (Get-Team | ?{$_.GroupID -eq $Team}).DisplayName
$TeamOwner = (Get-TeamUser -GroupId $Team | ?{$_.Role -eq 'Owner'}).Name
$TeamMember = (Get-TeamUser -GroupId $Team | ?{$_.Role -eq 'Member'}).Name
$TeamList = $TeamList + [PSCustomObject]@{TeamName = $TeamName; TeamObjectID = $TeamGUID; TeamOwners = $TeamOwner -join ', '; TeamMembers = $TeamMember -join ', '}
}
$TeamList | export-csv c:\temp\TeamsData.csv -NoTypeInformation
Create a Team Using PowerShell and add a member & channel
New-Team (MicrosoftTeamsPowerShell) | Microsoft Docs
This script creates a new private team, sets the owner of the team and disables the ability for members to create or update channels. It then goes on to add a user to the team and create a new channel.
$group = New-Team -DisplayName "<TeamName>" -Description "<Description>" -Visibility Private -Owner "<OwnerUPN/Email>" -AllowCreateUpdateChannels $False
Add-TeamUser -GroupId $group.GroupId -User "<MemberEmail/UPN>"
New-TeamChannel -GroupId $group.GroupId -DisplayName "<ChannelName>"
Once created you can unhide the group from Outlook via Set-UnifiedGroup (ExchangePowerShell) | Microsoft Docs But first you need to install the Exchange Online PowerShell Module (see Connect to Exchange Online PowerShell | Microsoft Docs)
Import-Module ExchangeOnlineManagement
Connect-ExchangeOnline
Once installed you can then use the following script to make Team mailbox visible and also autosubscribe new members.
Set-UnifiedGroup -Identity "<TeamName>" -HiddenFromExchangeClientsEnabled:$false -AutoSubscribeNewMembers
You can also manage Teams Channels and Membership from PowerShell. Some examples which all use the Teams PowerShell module.
Add a specific channel to all Teams
$Teams = Get-Team
foreach ($Team in $Teams) { New-TeamChannel -GroupId $Team.GroupID -DisplayName "<ChannelName>"}
Add a specific user to all Teams
$Teams = Get-Team
foreach ($Team in $Teams) { Add-TeamUser -GroupId $Team.GroupID -User <UserEmail/UPN> -Role Member}
Remove a specific channel from all Teams
$Teams = Get-Team
foreach ($Team in $Teams) { Remove-TeamChannel -GroupId $Team.GroupID -DisplayName "<ChannelName>"}
Remove a specific user from all Teams
$Teams = Get-Team
foreach ($Team in $Teams) { Remove-TeamUser -GroupId $Team.GroupID -User <UserEmail/UPN> -Role Member}
Download
Here is a text file with all the above scripts in that I used for testing purposes in preparing this blog. As always, please check before running as the responsibility is yours.
Other References
Whilst beyond what you need for MS-700 you may find these links useful:
- Update all modules script from @thewatchernode https://github.com/TheWatcherNode/blogaboutcloud/blob/master/Get-InstalledModulesUpdate.ps1
One thought on “MS-700 Useful PowerShell – Part 1”