Error: Parameter set cannot be resolved using specific named parameters

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
                }

kemppaik,
Welcome to the forum. :wave:t3:

Before we proceed: Please do not post images of code as this does not help at all. Instead post the plain text and format it as code.

When you post code, sample data, console output or error messages please format it as code using the preformatted text button ( </> ). Simply place your cursor on an empty line, click the button and paste your code.

Thanks in advance

Guide to Posting Code - Redux <---- Click :point_up_2:t4: :wink:

( !! Sometimes the preformatted text button hides behind the settings gear symbol. :wink: )

Where is $UserId defined for use in this section?

$params = @{
	"@odata.type" = "#microsoft.graph.aadUserConversationMember"
	"user@odata.bind" = "https://graph.microsoft.com/v1.0/users/$UserId"
	"roles" = @("owner")
}  

According to the Docs it looks to me like you’ve written everything syntax correct, but i suspect the error is coming from the hashtable being given to -BodyParameter

The $UserId is defined slightly above the code above.

I have a loop that iterates over each of the TeamMembers who should be part of the shared channel. I have their email and if they are members or owners. I’ve tried using their email and recently tried to use their UserId in $params.

                $MemberEmail = $TeamMember.UserEmail
                $Role = $TeamMember.Type
                $User = Get-MgUser -UserId $MemberEmail
                $UserId = $User.Id