Windows OS Hub
  • Windows Server
    • Windows Server 2022
    • Windows Server 2019
    • Windows Server 2016
    • Windows Server 2012 R2
    • Windows Server 2008 R2
    • SCCM
  • Active Directory
    • Active Directory Domain Services (AD DS)
    • Group Policies
  • Windows Clients
    • Windows 11
    • Windows 10
    • Windows 8
    • Windows 7
    • Windows XP
    • MS Office
    • Outlook
  • Virtualization
    • VMWare
    • Hyper-V
    • KVM
  • PowerShell
  • Exchange
  • Cloud
    • Azure
    • Microsoft 365
    • Office 365
  • Linux
    • CentOS
    • RHEL
    • Ubuntu
  • Home
  • About

Windows OS Hub

  • Windows Server
    • Windows Server 2022
    • Windows Server 2019
    • Windows Server 2016
    • Windows Server 2012 R2
    • Windows Server 2008 R2
    • SCCM
  • Active Directory
    • Active Directory Domain Services (AD DS)
    • Group Policies
  • Windows Clients
    • Windows 11
    • Windows 10
    • Windows 8
    • Windows 7
    • Windows XP
    • MS Office
    • Outlook
  • Virtualization
    • VMWare
    • Hyper-V
    • KVM
  • PowerShell
  • Exchange
  • Cloud
    • Azure
    • Microsoft 365
    • Office 365
  • Linux
    • CentOS
    • RHEL
    • Ubuntu

 Windows OS Hub / Microsoft 365 / Teams / Managing Microsoft Teams with PowerShell

August 15, 2022 Microsoft 365PowerShellTeams

Managing Microsoft Teams with PowerShell

The Microsoft Teams PowerShell module is designed to manage Teams from the command line. You can use the Teams module commands to quickly perform common administrative tasks or in automation scenarios. In this article, we will show how to install the Teams PowerShell module and look at typical commands a Microsoft 365 administrator may need to manage Teams.

Contents:
  • How to Install Microsoft Teams PowerShell Module?
  • How to Manage Microsoft Teams Using PowerShell Module?

How to Install Microsoft Teams PowerShell Module?

To install the Microsoft Teams module, you must have PowerShell 5.1 or newer installed on your computer. You can check the current PowerShell version using the command below:

$PSVersionTable.PSVersion

If necessary, update your PowerShell version.

You can install the MS Teams module from the PowerShell Gallery using this command:

Install-Module -Name MicrosoftTeams

install microsoftteams powershell module

To make sure that the Teams module is installed on your computer and display its version, run the command below:

Get-Module MicrosoftTeams –ListAvailable

You can also download and install the PowerShell module manually.

You can install a specific Teams module version from PSGallery. List available module versions:

Find-Module MicrosoftTeams -AllVersions

microsoft teams module versions

To install a specific version, run the command:

Install-Module -Name MicrosoftTeams -RequiredVersion 4.5.0

To update the MS Teams PowerShell module:

Update-Module -Name MicrosoftTeams

You can display a full list of cmdlets in the module:

Get-Command –Module MicrosoftTeams

list cmdlets in microsoftteams module

How to Manage Microsoft Teams Using PowerShell Module?

To connect to your Teams tenant in Microsoft 365 use this command:

Connect-MicrosoftTeams

Enter your user name and password. If the user’s Azure account has MFA enabled, you need to confirm your sign-in.

To use the Teams module, one of the following Azure roles must be assigned to your account:

  • Global Admin
  • Teams Service Admin
  • Teams Communications Admin
  • Teams Communications Support Engineer
  • Teams Communications Support Specialist

To display all teams in your tenant:
Get-Teams

To create a new private team in Teams:

New-Team –DisplayName SysOps

When creating a new team, a Microsoft 365 group is automatically created with workspaces in Yammer, PowerBI, and SharePoint workspaces, as well as an Exchange Online distribution group.

To display all team settings:

get-team -DisplayName sysops|fl

GroupId : xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxx
InternalId : [email protected]
DisplayName : SysOps
Description : SysOps Wiki Team
Visibility : Public
MailNickName : msteams_xxx12a
Classification :
Archived : False
AllowGiphy : True
GiphyContentRating : moderate
AllowStickersAndMemes : True
AllowCustomMemes : True
AllowGuestCreateUpdateChannels : False
AllowGuestDeleteChannels : False
AllowCreateUpdateChannels : True
AllowCreatePrivateChannels : True
AllowDeleteChannels : True
AllowAddRemoveApps : True
AllowCreateUpdateRemoveTabs : True
AllowCreateUpdateRemoveConnectors : True
AllowUserEditMessages : True
AllowUserDeleteMessages : True
AllowOwnerDeleteMessages : True
AllowTeamMentions : True
AllowChannelMentions : True
ShowInTeamsSearchAndSuggestions : True

You can change the team description and visibility:

get-team -DisplayName sysops| Set-Team -Description "SysOps Wiki" -Visibility "Public"

get-team - list microsoft team properties with powershell

To change a team picture:

get-team -DisplayName sysops | Set-TeamPicture -ImagePath c:\ps\corp_sysops.png

To add a user to the team:

get-team -DisplayName sysops| Add-TeamUser -User [email protected]

To add a team owner:

get-team -DisplayName sysops| Add-TeamUser -User [email protected] -Role Owner

You can add a user to all teams in your tenant using a simple PowerShell script:

$AllTeams = Get-Team
$UserToAdd = "[email protected]"
ForEach ($Team in $AllTeams)
{
Write-Host "Adding to $($Team.DisplayName)"
Add-TeamUser -GroupId $Team.GroupID -User $UserToAdd -Role Member
}

To display a list of users and owners of a team:

get-team -DisplayName sysops|Get-TeamUser

get-teamuser - list user of a team

To display members of all Teams groups and their owners:

$AllTeams = (Get-Team).GroupID
TeamList = @()
Foreach ($CurTeam in $AllTeams)
{ $TeamGUID = $CurTeam.ToString()
$TeamName = (Get-Team | ?{$_.GroupID -eq $CurTeam}).DisplayName
$TeamOwner = (Get-TeamUser -GroupId $CurTeam | ?{$_.Role -eq 'Owner'}).Name
$TeamMember = (Get-TeamUser -GroupId $CurTeam | ?{$_.Role -eq 'Member'}).Name
$TeamList = $TeamList + [PSCustomObject]@{TeamName = $TeamName; TeamObjectID = $TeamGUID; TeamOwners = $TeamOwner -join ', '; TeamMembers = $TeamMember -join ', '}
}
$TeamList |fl

List owners of a team

To remove a user from team owners and from a team:

get-team -DisplayName sysops| Remove-TeamUser -User [email protected] -Role Owner
get-team -DisplayName sysops| Remove-TeamUser -User [email protected]

To create a new private channel in an existing team, run the command below:

get-team -DisplayName sysops| New-TeamChannel -DisplayName "Windows_Wiki" -MembershipType Private

manage channel in microsoft teams with powershell

To add a user to a channel and assign him an owner:

get-team -DisplayName sysops| Add-TeamChannelUser -DisplayName “Windows_Wiki” -User [email protected] -Role Owner

To remove a user from a channel:

get-team -DisplayName sysops| Remove-TeamChannelUser -DisplayName "Windows_Wiki" -User [email protected] -Role Owner

If a team is not active, but you want to let users view its content, you can archive the team:

get-team -DisplayName sysops|Set-TeamArchivedState -Archived $true

To remove a channel:

get-team -DisplayName sysops | Remove-TeamChannel -DisplayName “Windows_Wiki”

To remove a team:

get-team -DisplayName sysops | Remove-Team

You can create a new Teams policy with New-CsTeamsMessagingPolicy:

New-CsTeamsMessagingPolicy –Identity polTeamsExternalUsers -AllowGiphy $false -AllowMemes $false –AllowUserChat $false

New-CsTeamsMessagingPolicy

Identity : Tag:polTeamsExternalUsers
Description :
AllowUrlPreviews : True
AllowOwnerDeleteMessage : False
AllowUserEditMessage : True
AllowUserDeleteMessage : True
AllowUserDeleteChat : True
AllowUserChat : False
AllowRemoveUser : True
AllowGiphy : False
GiphyRatingType : Moderate
AllowGiphyDisplay : True
AllowPasteInternetImage : True
AllowMemes : False
AllowImmersiveReader : True
AllowStickers : True
AllowUserTranslation : True
ReadReceiptsEnabledType : UserPreference
AllowPriorityMessages : True
AllowSmartReply : True
AllowSmartCompose : True
ChannelsInChatListEnabledType : DisabledUserOverride
AudioMessageEnabledType : ChatsAndChannels
ChatPermissionRole : Restricted
AllowFullChatPermissionUserToDeleteAnyMessage : False
AllowFluidCollaborate : False
AllowVideoMessages : True

To assign a Teams policy to a user:

Grant-CsTeamsMessagingPolicy -Identity [email protected] -PolicyName polTeamsExternalUsers

Or to all users with the specific attribute in AzureAD:

Get-CsOnlineUser -Filter {Department -like '*External*'} | Grant-CsTeamsMessagingPolicy -PolicyName polTeamsExternalUsers

After you finish working in PowerShell, remember to disconnect from Microsoft Teams:

Disconnect-MicrosoftTeams

0 comment
0
Facebook Twitter Google + Pinterest
previous post
Using Windows Update Delivery Optimization in Local Networks
next post
Configure SSL Connection Encryption in MS SQL Server

Related Reading

How to Connect VPN Before Windows Logon

November 14, 2023

Send Emails with Microsoft Graph API and PowerShell

November 6, 2023

Zabbix: How to Get Data from PowerShell Scripts

October 27, 2023

Tracking Printer Usage with Windows Event Viewer Logs

October 19, 2023

PowerShell: Configure Certificate-Based Authentication for Exchange Online (Azure)

October 15, 2023

Leave a Comment Cancel Reply

Categories

  • Active Directory
  • Group Policies
  • Exchange Server
  • Microsoft 365
  • Azure
  • Windows 11
  • Windows 10
  • Windows Server 2022
  • Windows Server 2019
  • Windows Server 2016
  • PowerShell
  • VMWare
  • Hyper-V
  • Linux
  • MS Office

Recent Posts

  • How to Connect VPN Before Windows Logon

    November 14, 2023
  • Removing Azure Arc Setup Feature on Windows Server 2022

    November 9, 2023
  • Using WPAD (Web Proxy Auto-Discovery Protocol) on Windows

    November 7, 2023
  • Send Emails with Microsoft Graph API and PowerShell

    November 6, 2023
  • Zabbix: How to Get Data from PowerShell Scripts

    October 27, 2023
  • Tracking Printer Usage with Windows Event Viewer Logs

    October 19, 2023
  • PowerShell: Configure Certificate-Based Authentication for Exchange Online (Azure)

    October 15, 2023
  • Reset Root Password in VMware ESXi

    October 12, 2023
  • How to Query and Change Teams User Presence Status with PowerShell

    October 8, 2023
  • How to Increase Size of Disk Partition in Ubuntu

    October 5, 2023

Follow us

  • Facebook
  • Twitter
  • Telegram
Popular Posts
  • Outlook Keeps Asking for Password on Windows
  • Checking User Sign-in Logs in Azure AD (Microsoft 365)
  • How to Manually Configure Exchange or Microsoft 365 Account in Outlook 365/2019/2016
  • Whitelist Domains and Email Addresses on Exchange Server and Microsoft 365
  • Search and Delete Emails from User Mailboxes on Exchange Server (Microsoft 365) with PowerShell
  • Blank Sign-in Screen in Office 365 Apps (Outlook, Teams, etc.)
  • Removing Built-in Teams Chat in Windows 11
Footer Logo

@2014 - 2023 - Windows OS Hub. All about operating systems for sysadmins


Back To Top