As with all PowerShell commands, there are often not many practical examples, and if there are, they don’t cover every scenario. The PowerShell Graph SDK has this exact issue. Though the documentation is excellent for listing all the commands, not every command has examples. In the documentation, one great thing is the bottom section labeled “Notes,” which outlines the object types in further detail. Though it may not seem helpful at first glance, it explains the property types required for executing the command. The following image is a part of the note section for the “New-MgTeam” command.

As you can see, it provides some critical information, such as the types of objects. In the screenshot, you can see various object types such as:

  • IMicrosoftGraphChannel[]
  • IMicrosoftGraphDriveItem
  • IMicrosoftGraphIdentitySet
  • IMicrosoftGraphUser

For example, searching the web for “IMicrosoftGraphIdentitySet” returns this documentation link: 

https://docs.microsoft.com/en-us/graph/api/resources/identityset?view=graph-rest-1.0#:~:text=Namespace%3A%20microsoft.graph%20The%20IdentitySet%20resource%20is%20a%20keyed,Here%20is%20a%20JSON%20representation%20of%20the%20resource

Though this link may not be super helpful, it does explain that this object type “represents a set of identities associated with various events for an item, such as created by or last modified by.” 

It also displays a JSON representation of the object.

{
  "application": {"@odata.type": "microsoft.graph.identity"},
  "device": {"@odata.type": "microsoft.graph.identity"},
  "user": {"@odata.type": "microsoft.graph.identity"}
}

Now that we understand the object type, plus further information such as the JSON representation, how does that help us to execute the PowerShell command?

Initially, you may think it is not helpful, but it is super beneficial for constructing the command. However, to ensure we get the values right, we can turn to Graph Explorer and review the returned values from the actual Graph call itself.

In the example of “New-MgTeam,” ideally, we want to see how to construct the properties quickly. To do this, using Graph Explorer, we need to follow a few steps.

Step 1: Launch Graph Explorer and log in to the Tenant

Step 2: Choose the Team to Query

  • Set the request type to “GET
  • Set the endpoint to “BETA
  • Set the URL to “https://graph.microsoft.com/beta/teams
  • Click “Run query
  • From the results section, choose a Team, and copy the “id” field value

Step 3: Query the selected Team

Step 4: Review the returned property format

As you can see, this returns the specific format for the property values you may want to utilize. If you’re going to view deeper information about the Team, simply adding a “/” at the end will display options of what’s available.

For example, changing the URL by adding “members” to the end returns the members of the team and displays the values in a hash-table format.

Modifying the URL again by using an ID of the returned members when executed returns specifics about the account.

https://graph.microsoft.com/beta/teams/0c83236a-7484-4128-b43c-f7f5011a581b/members/MCMjMSMjOWM3NjU5YzMtYWNmYS00MmU3LWI1NmEtNWI2NTNmMWI3YzYwIyMwYzgzMjM2YS03NDg0LTQxMjgtYjQzYy1mN2Y1MDExYTU4MWIjIzQwZjM5YmEwLWU5NjAtNDJiMC1iZDlhLTA2YjM5NTNjZGI3NA==

Looking at the returned values, you can see the object type again, along with properties requiring specific formats. For example, the “Roles” Property is a collection of values of the role assigned within the team.

Changing the ID to an account within the team assigned to roles reveals how to format the property.

As an example, if you want to assign a different user in the team the “Owner” role, you can use the following PowerShell, now that we know the format of the “Roles” property.

$memberid = "MCMjMSMjOWM3NjU5YzMtYWNmYS00MmU3LWI1NmEtNWI2NTNmMWI3YzYwIyMwYzgzMjM2YS03NDg0LTQxMjgtYjQzYy1mN2Y1MDExYTU4MWIjIzQwZjM5YmEwLWU5NjAtNDJiMC1iZDlhLTA2YjM5NTNjZGI3NA=="
$teamid = "0c83236a-7484-4128-b43c-f7f5011a581b"
$roles = @( "owner" )

$params = @{
	ConversationMemberId = $memberid
	TeamId = $teamid
	Roles = $roles
	AdditionalProperties = @{
		"@odata.type" = "#microsoft.graph.aadUserConversationMember";
	}
}

Update-MgTeamMember @params

Of course, this is a simple example of adding the required role to a user. A more advanced example is updating specific settings for a team, such as the “Fun Settings.”

$teamid = "0c83236a-7484-4128-b43c-f7f5011a581b"

$params = @{
	TeamId = $teamid
	FunSettings = @{ 
        	"allowGiphy" = "false"; 
        	"giphyContentRating" = "strict"; 
        	"allowStickersAndMemes" = "true"; 
        	"allowCustomMemes" = "true"; 
	}
}

Update-MgTeam @params

As you can see, the Graph Explorer tool is invaluable to identify the properties’ format, helping you execute the commands correctly. If you have not utilized it before, head over to “https://developer.microsoft.com/en-us/graph/graph-explorer,” log in and use some of the samples available within the tool.