24 C
Dubai
Thursday, March 28, 2024

Microsoft Teams PowerShell

Poweshell is simply amazing , it saved more than 3000 hours in my life. It made the impossible possible to work with Microsoft Products seamlessly. when it comes to managing large data sets or user base. It makes life simply easy. Microsoft Teams dynamic membership can happen only on the team level with Azure P1 license . But if you wish to have channels with large user base. PowerShell is your savior.  Otherwise your fingers are going to pain clicking it.  i have made as simple as possible using the existing cmdlets . if you wish to add any additional cmdlets please feel free to leave on comments.

Installing Teams Module

Find-Module MicrosoftTeams
Find-Module MicrosoftTeams | Install-Module

image

Using pre-Release Modules _ For Example Some Commands Available are only at pre-release

Before using pre-release modules make sure PowerShellGet Runs the latest version

Install-Module PowerShellGet -RequiredVersion 2.2.4.1

To use pre-release version – (Get-TeamChannelUser is available only on pre release version for now)

Install-Module -Name MicrosoftTeams -RequiredVersion 1.1.3-preview -AllowPrerelease

To use Production version –
Install-Module MicrosoftTeams –RequiredVersion 1.1.4

Production Versions – https://www.powershellgallery.com/packages/MicrosoftTeams

Connect-MicrosoftTeams

image

To List all Teams

Get-Team

image

To Get Channels within Team

Get-Team -DisplayName "Information Technology" | Get-TeamChannel

image

1. Copy Channel Members to another Channel

You can collect the GroupID of the team from the previous command

Get-TeamChannelUser -GroupId "50e33be9-GROUPIDOFTHETEAM4706544ab1a4" -DisplayName "ChannelName"

Now Save it to a Variable from Channel1

$SaveAllMembers = Get-TeamChannelUser -GroupId "50e33be9-GROUPIDOFTHETEAM4706544ab1a4" -DisplayName "ChannelName"

image

Now Add Same Set of Members to Channel2

$saveallmembers | ForEach-Object{Add-TeamChannelUser -GroupId "50e33be9GROUPIDOFTHETEAM706544ab1a4" -DisplayName "CHANNEL NAME" -User $_.user}

image

Removing Specific Channel user

Remove-TeamChannelUser -GroupId "50e33be9GROUPIDOFTHETEAM-4706544ab1a4" -DisplayName "Channel name" –User "zulqar@localhost"

image

Export Channel Members to CSV –

Get-TeamChannelUser -GroupId "50e33be9GROUPIDOFTHETEAM-4706544ab1a4" -DisplayName "Channel Name" | Select-Object User | Export-Csv TeamsChannelMembers.csv

image

Removing Members from Channels using CSV

Import-Csv .\TeamsChannelMembers.csv
Import-Csv .\TeamsChannelMembers.csv | ForEach-Object{Remove-TeamChannelUser -GroupId "50e33be9-GROUPIDOFTHETEAM-4706544ab1a4" -DisplayName "SD - NET" -User $_.User}

image

Adding Channel Members using CSV

Import-Csv .\TeamsChannelMembers.csv | ForEach-Object{Add-TeamChannelUser -GroupId "50e33be9GROUPIDOFTHETEAM-4706544ab1a4" -DisplayName "Channel Name" -User $_.User}

Adding Team Members using CSV

Import-Csv .\TeamsMembers.csv | ForEach-Object{Add-TeamUser -GroupId "000faf41-7fa8-0000-ac2d-2c180000af77" -User $_.User}}

To Display All Teams and Channels

Get-Team | ForEach-Object{Get-TeamChannel -GroupID $_.GroupID | FT DisplayName,Description,MembershipType}

 

Good to have – To Use Different Repositories –

Register-PSRepository –Name '_TempTestRepo' –SourceLocation 'https://www.poshtestgallery.com'

To List Registered Repositories –

Get-PSRepository | Fl 
Microsoft Remove - Pre-Release Versions from below Location - https://www.poshtestgallery.com/packages/MicrosoftTeams

If you hit below error - Update PowershellGet and Restart Powershell
PS C:\Scripts> Install-Module -Name MicrosoftTeams -RequiredVersion 1.1.3-preview -AllowPrerelease
Install-Module : Cannot process argument transformation on parameter 'RequiredVersion'. Cannot convert value
"1.1.3-preview" to type "System.Version". Error: "Input string was not in a correct format."
At line:1 char:54
+ ... ll-Module -Name MicrosoftTeams -RequiredVersion 1.1.3-preview -AllowP ...
+ CategoryInfo          : InvalidData: (:) [Install-Module], ParameterBindingArgumentTransformationException
+ FullyQualifiedErrorId : ParameterArgumentTransformationError,Install-Module
Satheshwaran Manoharan
Satheshwaran Manoharanhttps://www.azure365pro.com
Award-winning Technology Leader with a wealth of experience running large teams and diversified industry exposure in cloud computing. From shipping lines to rolling stocks.In-depth expertise in driving cloud adoption strategies and modernizing systems to cloud native. Specialized in Microsoft Cloud, DevOps, and Microsoft 365 Stack and conducted numerous successful projects worldwide. Also, Acting as a Technical Advisor for various start-ups.

Related Articles

9 COMMENTS

  1. hey im curious if its possible to use this module to directly manipulate chat conversations or if such a module exists. Specifically Im hoping to clear out conversations older than a specific age.

  2. Hi, I followed the instructions step by step, but I have this error message:
    Get-TeamChannelUser : The term ‘Get-TeamChannelUser’ is not recognized as a cmdlet name, function, executable program or script file. Check the spelling of the name or verify that the path is included and correct, then try again.
    In riga:1 car:1
    + Get-TeamChannelUser
    + ~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : ObjectNotFound: (Get-TeamChannelUser:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

    Can you help me ?
    thankyou !

  3. This was very helpful. I am receiving an error “BadGateway” when I attempt to modify your script to include “Role”. Am I doing something wrong?

    Import-Csv .\addChannelUsers.csv | ForEach-Object{Add-TeamChannelUser -GroupId $GroupId -DisplayName $_.cdisplayname -User $_.cuser -Role $_.crole}

  4. Display All Teams and Channels – Get-Team | ForEach-Object{Get-TeamChannel -GroupID $_.GroupID | FT DisplayName,Description,MembershipType}

    How do I export to CSV? I added Export-CSV but it doesn’t show all the info as it does when listing on PS. I’d like to export all Teams channels/groups their owners and members for each channel.
    Pls help! Thx!

  5. Hi, Satheswaran,

    Many thanks for the detailed version of script and it worked for me.

    Out of box, one more question I have here. Is there any teams chat can be exported to csv. I would like to downland each channels data with media.?

LEAVE A REPLY

Please enter your comment!
Please enter your name here

× How can I help you?