1- # Create team.
1+ # Switch to beta profile. This loads cmddlets that call MS Graph beta endpoint.
2+ Select-MgProfile - Name beta
3+
4+ # Create a new team.
25$TeamName = " 2020 Interns"
36New-MgTeam - DisplayName $TeamName - Description $TeamName `
47 - AdditionalProperties @ {
58 " [email protected] " = " https://graph.microsoft.com/beta/teamsTemplates('standard')" 69 }
710
8- # Get created team.
11+ # Filter groups by displayName and resourceProvisioningOptions to find team.
912$InternsTeam = Get-MgGroup - Filter " StartsWith(DisplayName, '$TeamName ')" `
1013 | Where-Object { $_.ResourceProvisioningOptions -Contains " Team" }
1114
1215# Add team owner.
16+ $teamOwner = Get-MgUser - UserId " {TEAM_OWNER_UPN}"
1317New-MgTeamMember - TeamId $InternsTeam.Id - Roles " owner" `
1418 - AdditionalProperties @ {
1519 " @odata.type" = " #microsoft.graph.aadUserConversationMember" ;
16- " [email protected] " = " https://graph.microsoft.com/beta/users/" + $teamOwnwerId 20+ " [email protected] " = " https://graph.microsoft.com/beta/users/" + $teamOwner .Id 1721 }
1822
23+ # Filter users to find users who have a UPN that starts with 't-'.
24+ $TeamMembers = Get-MgUser - Filter " startswith(userPrincipalName, 't-')"
25+
1926# Add team members.
2027foreach ($teamMember in $TeamMembers ) {
2128 New-MgTeamMember - TeamId $InternsTeam.Id - Roles " member" `
@@ -25,6 +32,14 @@ foreach ($teamMember in $TeamMembers) {
2532 }
2633}
2734
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+
2843# Delete team.
2944Remove-MgGroup - GroupId $InternsTeam.Id
3045
@@ -37,14 +52,21 @@ Get-MgChat
3752Get-MgChatMessage - chatId $chatId
3853
3954# Send a message in that 1:1 chat
40- New-MgChatMessage - chatId $chatId - BodyContent " Hi from VSCode again!"
55+ New-MgChatMessage - chatId $chatId - Body @ { Content = " Hi from VSCode again!" }
4156
4257# Mention a user in a channel message.
43- $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+ }
4464
4565New-MgTeamChannelMessage - ChannelId $ChannelId - TeamId $TeamId `
46- - BodyContentType " html" `
47- - 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+ } `
4870 - Mentions @ ( `
4971 @ { `
5072 id = 0 ; `
0 commit comments