I have a PowerShell script that is creating a Microsoft Team and Shared Channels. For the shared channels there are specific users that I want to assign. When I go to execute New-MgTeamChannelMember, I’m consistently getting this message:
“New-MgTeamChannelMember: Parameter set cannot be resolved using the specified named parameters. One or more parameters issued cannot be used together or an insufficient number of parameters were provided.”
Below is a screenshot of my code. I’m fairly new to PowerShell and I’ve been looking at the code over and over but I can’t seem to get past this error. I’ve even tried a slightly different $params setup (commented out in the screenshot) but still no luck.
Has anyone encountered anything like this? Any suggestions on how to get past this?
Thanks.
# Get the ID for the newly created Team and Channel
$Team = Get-MgTeam -Filter "displayName eq '$TeamClientName'" -Property "id, description"
$TeamId = $Team.Id
$Channel = Get-MgTeamChannel -TeamId $TeamId -Filter "displayName eq '$ChannelDisplayName'" | Select-Object Id
$ChannelId = $Channel.Id
$params = @{
"@odata.type" = "#microsoft.graph.aadUserConversationMember"
"user@odata.bind" = "https://graph.microsoft.com/v1.0/users/$UserId"
"roles" = @("owner")
}
# $params = @{
# "@odata.type" = "#microsoft.graph.aadUserConversationMember"
# roles = @(
# )
# "user@odata.bind" = "https://graph.microsoft.com/v1.0/users('$MemberEmail')"
# }
try
{
New-MgTeamChannelMember -TeamId $TeamId -ChannelId $ChannelId -BodyParameter $params
}
catch
{
$exception = $_.Exception
}