Jul 29 2021 02:29 AM
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
Jul 29 2021 07:41 AM
SolutionJul 29 2021 08:48 PM
Nov 09 2022 08:24 AM
@StanleyHao @Christopher Hoard
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=='
Get-MgChat (Microsoft.Graph.Teams) | Microsoft Learn
Remove-MgChatMember (Microsoft.Graph.Teams) | Microsoft Learn
Hope it helps.