Microsoft Teams: PowerShell script to add Team owners as a Team members to resolve “Failed to add plan” issue while adding planner to Team which are created using Graph APIs

Failed to add planner in Teams

Hi All,

LIFE IS BEAUTIFUL 🙂 I hope we all are safe:) STAY SAFE, STAY HEALTHY 🙂 STAY HOME 🙂

In my previous article related to Microsoft Teams we discussed the issue while adding Planner to Teams which are created using Graph APIs and workaround – Microsoft Teams : “Failed to create the plan” error while adding Planner to Teams which are created using Graph APIs

Microsoft Teams : “Failed to create the plan” error while adding Planner to Teams which are created using Graph APIs
Fig1 : Microsoft Teams : “Failed to create the plan” error while adding Planner to Teams which are created using Graph APIs

If you didn’t read it yet, kindly please have a look once.

So workaround is adding Owners as Members as well and it resolved the issue. So as discussed in the article we changed the code and Owners could successfully add the Planned to their new Teams.

But then the issue remains same for existing teams, so one of the option is to write PowerShell script and hence this article 🙂

Background: We were provisioning Teams using Microsoft Graph APIs. We have our custom Teams creations form where user can order the Team. We are storing all Team orders in a custom SharePoint list called “TeamsOrder”

So here are the high level steps

  • Connect to Microsoft 365
  • Get the client context
  • Get the Web and List
  • Read all the existing Teams Items from our custom SharePoint list “TeamsOrder” which are created before given date
  • From DisplayName Get the Team
  • Get the Team Owners
  • Add the Team Owners as a Members

Detailed script

  • Get the user details – Here we are storing user details in a text file on file system having two lines in following format
    • UserName
    • Password
  • Connect to Microsoft 365
  • Get the Client Context from the site collection where we need to read list and get the teams
  • Get the web object to get list
  • Read the list and get list items – Kindly please note query for getting list items is as per our customer requirement :). You can changes with the respective your required fields and values
  • Now get the teams from DisplayName field – Get-Team -DisplayName <Team Display Name>
  • If Team exists then get the team owners – Get-TeamUser -GroupId <Team group id> -Role Owner
  • Loop through all team owners and add them as members – Add-TeamUser -GroupId -User <User> -Role Member

Complete Script :

References:

Thanks for reading 🙂 If its worth at least reading once, kindly please like and share. SHARING IS CARING 🙂

Enjoy the beautiful life 🙂 Have a FUN 🙂 HAVE A SAFE LIFE 🙂 TAKE CARE 🙂

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: