I’m attempting to put together a code where it can just bulk remove all users from all private channels except owners.
Im struggling to put together a script that just refers to each row user in csv, and remove them from any existing private channels they are currently in the MS Teams site.
$groupID = (Get-Team -displayname "R26").GroupId
$csv = Import-Csv -Path "C:\Users\Michael\Documents\WindowsPowerShell\AllDetailsChanged.csv"
$User = Get-TeamUser -GroupId $groupID
$Channel = Get-TeamChannel -GroupId $GroupID -MembershipType Private
$Channeluser = Get-TeamChannelUser -GroupId $groupID -DisplayName $row.channel
foreach($row in $csv){
if (($row.role -eq "Member") -and ($row.user -in $csv.User))
{
Write-Host "Removing from channel " -NoNewline -ForegroundColor Magenta
Write-Host $row.user
Remove-TeamChannelUser -Groupid $groupid -DisplayName $channel.DisplayName -User $row.user
}
}
This is error i recieve
Remove-TeamChannelUser : A positional parameter cannot be found that accepts
argument '$channel.DisplayName'.
At C:\Users\Michael\Documents\WindowsPowerShell Scripts\testestestestt.ps1:12
char:9
+ Remove-TeamChannelUser -Groupid $groupid -DisplayName ForEach ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Remove-TeamChannelUser], Par
ameterBindingException
+ FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.Teams.PowerS
hell.TeamsCmdlets.RemoveTeamChannelUser