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

Commit 2b04c3f

Browse files
calebkiagebaywet
andauthored
Chore/samples (#117)
* Add samples. Co-authored-by: Vincent Biret <[email protected]>
1 parent c44876d commit 2b04c3f

File tree

6 files changed

+245
-0
lines changed

6 files changed

+245
-0
lines changed

samples/1-Login.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
## Login
2+
3+
### Login with default client id & tenant id
4+
5+
```sh
6+
mgc login --scopes User.ReadWrite Mail.ReadWrite
7+
```
8+
9+
### Login with custom client id & tenant id
10+
11+
```sh
12+
mgc login --scopes User.ReadWrite Mail.ReadWrite --client-id <client id> --tenant-id <tenant id>
13+
```
14+
15+
### Login using previously consented permissions
16+
17+
```sh
18+
mgc login --scopes User.ReadWrite Mail.ReadWrite --client-id <client id> --tenant-id <tenant id>
19+
```
20+
21+
## Logout
22+
23+
Forget access tokens
24+
25+
```sh
26+
mgc logout
27+
```

samples/2-TenantInformation.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
## Tenant information
2+
3+
### Organization contact details
4+
5+
```sh
6+
mgc organization list
7+
```
8+
9+
```sh
10+
mgc organization list --select "DisplayName, City, State, Country, PostalCode, BusinessPhones"
11+
```
12+
13+
### List application registrations in the tenant
14+
15+
```sh
16+
mgc organization list --select "DisplayName, id, SignInAudience"
17+
```
18+
19+
### List service principals in the tenant
20+
21+
```sh
22+
mgc organization list --select "id, AppDisplayName" --query "value[?contains(appDisplayName, 'powershell')]"
23+
```

samples/3-UsersAndGroups.md

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
## Microsoft Graph Users and Groups Snippets
2+
3+
### List of Users
4+
5+
```sh
6+
mgc users list --select "id, displayName, OfficeLocation, BusinessPhones"
7+
```
8+
9+
### List users with count
10+
11+
```sh
12+
mgc users list --top 5 --count --consistency-level eventual
13+
```
14+
15+
### List of users with no Office Location
16+
17+
```sh
18+
mgc users list --select "id, displayName, OfficeLocation, BusinessPhones" --query "value[?!officeLocation]"
19+
```
20+
21+
### Update the location of the user
22+
23+
```sh
24+
mgc users item patch --user-id <UserId> --body '{"officeLocation": "NewLocation"}'
25+
```
26+
27+
### Get all Groups
28+
29+
```sh
30+
mgc groups list --select "id, DisplayName, GroupTypes"
31+
```
32+
33+
### Get all unified (Microsoft 365 Groups) Groups
34+
35+
```sh
36+
mgc groups list --filter "groupTypes/any(c:c eq 'Unified')"
37+
```
38+
39+
### Get-Details of a single Group
40+
41+
```sh
42+
mgc groups item get --group-id <GroupId>
43+
```
44+
45+
### Get Owners of a Group
46+
47+
```sh
48+
mgc groups item owners list --group-id <GroupId>
49+
```
50+
51+
### Get Members of a Group
52+
53+
```sh
54+
mgc groups members list --group-id <GroupId>
55+
```
56+
57+
### Get your mail
58+
59+
```sh
60+
mgc users item messages list --user-id <UserId> --filter "contains(subject,'Marketing')" --select "sentDateTime, subject"
61+
```
62+
63+
### New Group
64+
65+
```sh
66+
mgc groups create --body '{"displayName": "PowerFam", "mailEnabled": false, "mailNickName": "powerfam", "securityEnabled": true}'
67+
```
68+
69+
### Remove Group
70+
71+
```sh
72+
mgc groups item delete --group-id <GroupId>
73+
```
74+
75+
### Create a new User
76+
77+
```sh
78+
mgc users create --body '{"displayName": "Bob Brown", "accountEnabled": true, "passwordProfile": {"password": "password"},\
79+
"mailNickname": "Bob.Brown", "userPrincipalName": "bob.brown@{tenantdomain}"}'
80+
```

samples/4-Teams.md

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
### Create a new team
2+
3+
```sh
4+
mgc teams create --body '{"displayName": "2020 Interns", "description": "2020 Interns", \
5+
"additionalProperties": {
6+
"[email protected]" = "https://graph.microsoft.com/v1.0/teamsTemplates('standard')"
7+
}}'
8+
```
9+
10+
### Filter groups by displayName and resourceProvisioningOptions to find team
11+
12+
```sh
13+
mgc groups list --filter "StartsWith(DisplayName, '$TeamName')" --query "value[?contains(resourceProvisioningOptions, 'Team')]"
14+
```
15+
16+
### Add team owner
17+
18+
```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\
23+
}, "roles": ["owner"]}'
24+
```
25+
26+
### Send a welcome message to the channel
27+
28+
```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!"}}'
31+
```
32+
33+
### Delete team
34+
35+
```sh
36+
mgc groups delete --group-id <GroupId>
37+
```
38+
39+
### Teams Chat snippets
40+
41+
#### Get list of 1:1 chats
42+
43+
```sh
44+
mgc chats list
45+
```
46+
47+
#### Get Messages from Chat
48+
49+
```sh
50+
mgc chats item messages list --chat-id <ChatId>
51+
```
52+
53+
#### Send a message in that 1:1 chat
54+
55+
```sh
56+
mgc chats item messages create --chat-id <ChatId> --body '{"body": {"content": "Hi from CLI!"}}'
57+
```
58+
59+
#### Mention a user in a channel message
60+
61+
```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"}}}]}'
65+
```

samples/5-Sites.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
## Microsoft Graph Sites Snippets
2+
3+
### Get root site
4+
5+
```sh
6+
mgc sites item get --site-id root --select "id, displayName"
7+
```
8+
9+
### Search for sites
10+
11+
```sh
12+
mgc sites list --search "marketing" --select "displayName, description, webUrl"
13+
```
14+
15+
### Get Id for marketing site
16+
17+
```sh
18+
mgc sites list --search "marketing" --select id
19+
```
20+
21+
### Get Site Pages
22+
23+
```sh
24+
mgc sites item sites list --site-id <SiteId>
25+
```
26+
27+
### Get Site Lists
28+
29+
```sh
30+
mgc sites item sites list --site-id <SiteId> --select "id, displayName"
31+
```
32+
33+
### Get Document Libraries
34+
35+
```sh
36+
mgc sites item drive get --site-id <SiteId>
37+
```

samples/6-Drives.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
## Drive snippets
2+
3+
### Get drives
4+
5+
```sh
6+
mgc drives list
7+
```
8+
9+
### Get drive list
10+
11+
```sh
12+
mgc drives item list get --drive-id <DriveId>
13+
```

0 commit comments

Comments
 (0)