Forum Discussion

StanleyHao's avatar
StanleyHao
Copper Contributor
Jul 29, 2021
Solved

how to remove unlicensed people from group chat by powershell?

hi gents,

 

i have a request to bulk remove unlicensed people from chat group, which is self-organized by random users

 

since unlicensed people are in many chat groups, manual way costs too much time, so i am wondering if there is a programming way to do the job

 

thanks for your ideas

3 Replies

  • Hi StanleyHao

    Sorry, nothing in the PowerShell cmdlets which point to being able to do this programmatically.

    https://docs.microsoft.com/en-us/powershell/teams/intro?view=teams-ps

    I would recommend raising it on uservoice (https://microsoftteams.uservoice.com/forums/555103-public) whilst it is still around in order to raise it as a new feature. As far as I know this is the only possible way is

    https://support.microsoft.com/en-gb/office/leave-or-remove-someone-from-a-group-chat-7db55a67-0ba4-4409-a399-5ed502a1d094

    Note - If someone leaves or is removed from a group chat, their messages will remain in the group chat history

    Hope that answers your question

    Best, Chris
    • StanleyHao's avatar
      StanleyHao
      Copper Contributor
      Hi ChrisHoardMVP

      Thanks for your replies, similar result as my guess and researches. It is very helpful.

      I'll go to uservoice to raise the request.

      • ExSportCZ's avatar
        ExSportCZ
        Copper Contributor

        StanleyHao ChrisHoardMVP 

        It is possible via MS Graph so if someone will find this thread, this may be still helpful:

        #Install-Module -Name Microsoft.Graph (big module!)
        Connect-MgGraph -Scopes Chat.ReadBasic,ChatMember.ReadWrite
        $mbrs = $null
        Get-MgChat -All|where chattype -eq 'group'|%{
        	$chatgrps = $_
        	$mbr = Get-MgChatMember -ChatId $_.Id
        	$mbrs += ,$(''|select @{n='Topic';e={$chatgrps.Topic}},Roles,@{n='ChatType';e={$chatgrps.ChatType}},@{n='CreatedDateTime';e={$chatgrps.CreatedDateTime}},@{n='LastUpdatedDateTime';e={$chatgrps.LastUpdatedDateTime}},@{n='ChatId';e={$chatgrps.Id}},@{n='MembersId';e={$mbr.Id}},@{n='Members';e={$mbr.displayname}})
        }
        $mbrs|where members -Contains '{Name of the user for removal}'|fl *

        This will list all groups where user is joined and its ChatId and MemberId.
        Below code (with correct ChatId and MemberId) will remove user from group.

        Remove-MgChatMember -ChatId '19:adfgdfgfdff09f9f8cdhdghhfdff4607f@thread.v2' -ConversationMemberId 'MCMfghgfhfghfghJhOGItYgfhfghgf2YfffffZjM2NzIyZjNhIyMxOTphNGQ1NWJlNzAxhgfhfghfg2RmMmJlYWY0NjA3ZkB0aHJlYWQgfhgfhgfNi1iNTRmLTE5fghgfgZTA0MWYyZA=='

        https://learn.microsoft.com/en-us/powershell/module/microsoft.graph.teams/get-mgchat?view=graph-powershell-1.0

        https://learn.microsoft.com/en-us/powershell/module/microsoft.graph.teams/remove-mgchatmember?view=graph-powershell-1.0

         

        Hope it helps.

Resources