[英]How do I remove a User from a Teams Shared Channel if they are not a member of a certain security group?
I'm trying to automate the removal of users from a shared channel that are not part of a dynamic security group.我正在尝试自动从不属于动态安全组的共享频道中删除用户。 I think I'm heading down the right path, but I'm relatively new to PS scripting.
我认为我正朝着正确的方向前进,但我对 PS 脚本编写还比较陌生。
$securitygroupId = "The Security Group"
$channelgroupId = "The GroupId of the host AzureAD Group"
$channelname = "Name of the Shared Channel"
Get-TeamChannelUser -GroupId $channelgroupId -DisplayName $channelname |
ForEach-Object {$channelusergroups = Get-AzureADUserMembership -ObjectId $_.UserId | Select ObjectId
if ($channelusergroups -NotContains $securitygroupId)
{Remove-TeamChannelUser -GroupId $channelgroupId -DisplayName $channelname -User $_.User
}
}
It removes the users right now even if they are in the security group.它现在删除用户,即使他们在安全组中。
I learned that if you put "-expand" after "select", the search will find the ObjectId of the security group in the pipeline.我了解到,如果在“select”之后加上“-expand”,搜索将在管道中找到安全组的 ObjectId。 Hope this helps someone else!
希望这可以帮助别人! -Cheers
-干杯
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.