1+ # Switch to beta profile. This loads cmdlets that call MS Graph beta endpoint.
2+ Select-MgProfile - Name beta
3+
4+ # Create a new team.
5+ $TeamName = " 2020 Interns"
6+ New-MgTeam - DisplayName $TeamName - Description $TeamName `
7+ - AdditionalProperties @ {
8+ " [email protected] " = " https://graph.microsoft.com/beta/teamsTemplates('standard')" 9+ }
10+
11+ # Filter groups by displayName and resourceProvisioningOptions to find team.
12+ $InternsTeam = Get-MgGroup - Filter " StartsWith(DisplayName, '$TeamName ')" `
13+ | Where-Object { $_.ResourceProvisioningOptions -Contains " Team" }
14+
15+ # Add team owner.
16+ $teamOwner = Get-MgUser - UserId " {TEAM_OWNER_UPN}"
17+ New-MgTeamMember - TeamId $InternsTeam.Id - Roles " owner" `
18+ - AdditionalProperties @ {
19+ " @odata.type" = " #microsoft.graph.aadUserConversationMember" ;
20+ " [email protected] " = " https://graph.microsoft.com/beta/users/" + $teamOwner.Id 21+ }
22+
23+ # Filter users to find users who have a UPN that starts with 't-'.
24+ $TeamMembers = Get-MgUser - Filter " startswith(userPrincipalName, 't-')"
25+
26+ # Add team members.
27+ foreach ($teamMember in $TeamMembers ) {
28+ New-MgTeamMember - TeamId $InternsTeam.Id - Roles " member" `
29+ - AdditionalProperties @ {
30+ " @odata.type" = " #microsoft.graph.aadUserConversationMember" ;
31+ " [email protected] " = " https://graph.microsoft.com/beta/users/" + $teamMember.Id 32+ }
33+ }
34+
35+ # Send a welcome message to the channel.
36+ $PrimaryChannel = Get-MgTeamPrimaryChannel - TeamId $InternsTeam.Id
37+ New-MgTeamChannelMessage - TeamId $InternsTeam.Id `
38+ - ChannelId $PrimaryChannel.Id `
39+ - Body @ {
40+ Content = " Welcome to Teams!"
41+ }
42+
43+ # Delete team.
44+ Remove-MgGroup - GroupId $InternsTeam.Id
45+
146# Teams Chat snippets
247
348# Get list of 1:1 chats
@@ -7,17 +52,24 @@ Get-MgChat
752Get-MgChatMessage - chatId $chatId
853
954# Send a message in that 1:1 chat
10- New-MgChatMessage - chatId $chatId - BodyContent " Hi from VSCode again!"
55+ New-MgChatMessage - chatId $chatId - Body @ { Content = " Hi from VSCode again!" }
1156
1257# Mention a user in a channel message.
13- $UserToMention = Get-MGUser - UserId $userUPN
58+ $User = Get-MgUser - UserId $userUPN | select id, displayName, userIdentityType
59+ $UserToMention = @ {
60+ Id = $User.Id ;
61+ DisplayName = $User.DisplayName ;
62+ UserIdentityType = " aadUser" ;
63+ }
1464
1565New-MgTeamChannelMessage - ChannelId $ChannelId - TeamId $TeamId `
16- - BodyContentType " html" `
17- - BodyContent " Welcome to the channel! <at id='0'>$ ( $UserToMention.DisplayName ) </at>" `
66+ - Body @ { `
67+ ContentType = " html" ; `
68+ Content = " Welcome to the channel! <at id='0'>$ ( $UserToMention.DisplayName ) </at>" `
69+ } `
1870 - Mentions @ ( `
1971 @ { `
2072 id = 0 ; `
2173 mentionText = $UserToMention.DisplayName ; `
2274 mentioned = @ {user = $UserToMention } `
23- })
75+ })
0 commit comments