Skip to content
This repository was archived by the owner on Aug 29, 2025. It is now read-only.

Commit df38fac

Browse files
authored
Fix samples (#165)
* Fix users and groups samples * Update teams samples
1 parent 5902271 commit df38fac

File tree

2 files changed

+106
-13
lines changed

2 files changed

+106
-13
lines changed

samples/3-UsersAndGroups.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,15 @@ mgc users list --select "id, displayName, OfficeLocation, BusinessPhones" --quer
2828

2929
### Update the location of the user
3030

31+
Powershell:
32+
33+
```powershell
34+
$body = ConvertTo-Json '{"officeLocation": "NewLocation"}'
35+
mgc users item patch --user-id <UserId> --body $body
36+
```
37+
38+
Bash:
39+
3140
```sh
3241
mgc users item patch --user-id <UserId> --body '{"officeLocation": "NewLocation"}'
3342
```
@@ -70,6 +79,15 @@ mgc users item messages list --user-id <UserId> --filter "contains(subject,'Mark
7079

7180
### New Group
7281

82+
Powershell:
83+
84+
```powershell
85+
$body = ConvertTo-Json '{"displayName": "PowerFam", "mailEnabled": false, "mailNickName": "powerfam", "securityEnabled": true}'
86+
mgc groups create --body $body
87+
```
88+
89+
Bash:
90+
7391
```sh
7492
mgc groups create --body '{"displayName": "PowerFam", "mailEnabled": false, "mailNickName": "powerfam", "securityEnabled": true}'
7593
```
@@ -82,6 +100,16 @@ mgc groups item delete --group-id <GroupId>
82100

83101
### Create a new User
84102

103+
PowerShell:
104+
105+
```powershell
106+
$body = ConvertTo-Json '{"displayName": "Bob Brown", "accountEnabled": true, "passwordProfile": {"password": "password"},\
107+
"mailNickname": "Bob.Brown", "userPrincipalName": "bob.brown@{tenantdomain}"}'
108+
mgc users create --body $body
109+
```
110+
111+
Bash:
112+
85113
```sh
86114
mgc users create --body '{"displayName": "Bob Brown", "accountEnabled": true, "passwordProfile": {"password": "password"},\
87115
"mailNickname": "Bob.Brown", "userPrincipalName": "bob.brown@{tenantdomain}"}'

samples/4-Teams.md

Lines changed: 78 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,90 @@
11
### Create a new team
22

3+
PowerShell:
4+
5+
```powershell
6+
$TeamName = "2020 Interns"
7+
$body = ConvertTo-Json '{"displayName": $TeamName, "description": $TeamName, "additionalProperties": { "[email protected]": "https://graph.microsoft.com/v1.0/teamsTemplates('standard')"}}'
8+
mgc teams create --body $body
9+
```
10+
11+
Bash:
12+
313
```sh
4-
mgc teams create --body '{"displayName": "2020 Interns", "description": "2020 Interns", \
14+
TeamName = "2020 Interns"
15+
mgc teams create --body '{"displayName": $TeamName, "description": $TeamName,
516
"additionalProperties": {
6-
"[email protected]" = "https://graph.microsoft.com/v1.0/teamsTemplates('standard')"
17+
"[email protected]": "https://graph.microsoft.com/v1.0/teamsTemplates('standard')"
718
}}'
819
```
920

1021
### Filter groups by displayName and resourceProvisioningOptions to find team
1122

23+
PowerShell:
24+
25+
```powershell
26+
$InternsTeam = mgc groups list --filter "StartsWith(DisplayName, '$TeamName')" --query "value[?contains(resourceProvisioningOptions, 'Team')]"
27+
```
28+
29+
Bash:
30+
1231
```sh
13-
mgc groups list --filter "StartsWith(DisplayName, '$TeamName')" --query "value[?contains(resourceProvisioningOptions, 'Team')]"
32+
InternsTeam=$(mgc groups list --filter "StartsWith(DisplayName, '$TeamName')" --query "value[?contains(resourceProvisioningOptions, 'Team')]")
1433
```
1534

1635
### Add team owner
1736

37+
PowerShell:
38+
39+
```powershell
40+
$teamOwner=mgc users get --user-id "{TEAM_OWNER_UPN}"
41+
mgc teams item members create --team-id $InternsTeam.id --body '{"additionalProperties": {
42+
"@odata.type": "#microsoft.graph.aadUserConversationMember",
43+
"[email protected]": "https://graph.microsoft.com/v1.0/users/" + $teamOwner.id
44+
}, "roles": ["owner"]}'
45+
```
46+
47+
Bash:
48+
1849
```sh
19-
mgc users get --user-id "{TEAM_OWNER_UPN}"
20-
mgc teams item members create --team-id <TeamId> --body '{"additionalProperties": {\
21-
"@odata.type": "#microsoft.graph.aadUserConversationMember",\
22-
"[email protected]": "https://graph.microsoft.com/v1.0/users/" + $teamOwner.id\
50+
teamOwnerId=$(mgc users get --user-id "{TEAM_OWNER_UPN}" | grep -o '"id": "[^"]*' | grep -o '[^"]*$')
51+
teamId=$(echo $InternsTeam | grep -o '"id": "[^"]*' | grep -o '[^"]*$')
52+
53+
mgc teams item members create --team-id $teamId --body '{"additionalProperties": {
54+
"@odata.type": "#microsoft.graph.aadUserConversationMember",
55+
"[email protected]": "https://graph.microsoft.com/v1.0/users/" + $teamOwnerId
2356
}, "roles": ["owner"]}'
2457
```
2558

2659
### Send a welcome message to the channel
2760

61+
PowerShell:
62+
63+
```powershell
64+
$PrimaryChannel = mgc teams item primary-channel get --team-id $InternsTeam.id
65+
$body = ConvertTo-Json '{"body": {"content": "Welcome to Teams!"}}'
66+
mgc teams item channels item messages create --team-id $InternsTeam.id --channel-id $PrimaryChannel.id --body $body
67+
```
68+
69+
Bash:
70+
2871
```sh
29-
mgc teams item primary-channel get --team-id <TeamId>
30-
mgc teams item channels item messages create --team-id <TeamId> --channel-id <ChannelId> --body '{"body": {"content": "Welcome to Teams!"}}'
72+
PrimaryChannelId=$(mgc teams item primary-channel get --team-id $teamId | grep -o '"id": "[^"]*' | grep -o '[^"]*$')
73+
mgc teams item channels item messages create --team-id $teamId --channel-id $PrimaryChannelId --body '{"body": {"content": "Welcome to Teams!"}}'
3174
```
3275

3376
### Delete team
3477

78+
PowerShell:
79+
80+
```powershell
81+
mgc groups delete --group-id $InternsTeam.id
82+
```
83+
84+
Bash:
85+
3586
```sh
36-
mgc groups delete --group-id <GroupId>
87+
mgc groups delete --group-id $teamId
3788
```
3889

3990
### Teams Chat snippets
@@ -58,8 +109,22 @@ mgc chats item messages create --chat-id <ChatId> --body '{"body": {"content": "
58109

59110
#### Mention a user in a channel message
60111

112+
PowerShell:
113+
114+
```powershell
115+
$user = mgc users item get --user-id <UserId> --select "id, displayName, userIdentityType"
116+
$body = ConvertTo-Json '{"body": {"contentType": "html", "content": "Welcome to the channel <at id=\'0\'>${user.displayName}</at>!"}, "mentions": [{"id": 0, "mentionText": "${user.displayName}", "mentioned": {"user": {"id": "${user.id}", "displayName": "${user.displayName}", "userIdentityType": "${user.userIdentityType}"}}}]}'
117+
mgc teams item channels item messages create --team-id <TeamId> --channel-id $PrimaryChannel.id \
118+
--body $body
119+
```
120+
121+
Bash:
122+
61123
```sh
62-
mgc users item get --user-id <UserId> --select "id, displayName, userIdentityType"
63-
mgc teams item channels item messages create --team-id <TeamId> --channel-id <ChannelId> \
64-
--body $'{"body": {"contentType": "html", "content": "Welcome to the channel <at id=\'0\'>[DisplayName]</at>!"}, "mentions": [{"id": 0, "mentionText": "[DisplayName]", "mentioned": {"user": {"id": "[id]", "displayName": "[DisplayName]", "userIdentityType": "aadUser"}}}]}'
124+
user=$(mgc users item get --user-id <UserId> --select "id, displayName, userIdentityType")
125+
userId=$(echo $user | grep -o '"id": "[^"]*' | grep -o '[^"]*$')
126+
userDisplayName=$(echo $user | grep -o '"displayName": "[^"]*' | grep -o '[^"]*$')
127+
userIdentityType=$(echo $user | grep -o '"userIdentityType": "[^"]*' | grep -o '[^"]*$')
128+
mgc teams item channels item messages create --team-id <TeamId> --channel-id $PrimaryChannelId \
129+
--body '{"body": {"contentType": "html", "content": "Welcome to the channel <at id=\'0\'>${userDisplayName}</at>!"}, "mentions": [{"id": 0, "mentionText": "${userDisplayName}", "mentioned": {"user": {"id": "${userId}", "displayName": "${userDisplayName}", "userIdentityType": "${userIdentityType}"}}}]}'
65130
```

0 commit comments

Comments
 (0)