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
+
1
46
# Teams Chat snippets
2
47
3
48
# Get list of 1:1 chats
@@ -7,17 +52,24 @@ Get-MgChat
7
52
Get-MgChatMessage - chatId $chatId
8
53
9
54
# 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!" }
11
56
12
57
# 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
+ }
14
64
15
65
New-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
+ } `
18
70
- Mentions @ ( `
19
71
@ { `
20
72
id = 0 ; `
21
73
mentionText = $UserToMention.DisplayName ; `
22
74
mentioned = @ {user = $UserToMention } `
23
- })
75
+ })
0 commit comments