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

Commit 88e87b3

Browse files
authored
Merge pull request #259 from microsoftgraph/readme-patch-1
Update README.md with feedback
2 parents 3525418 + af1974d commit 88e87b3

File tree

1 file changed

+163
-24
lines changed

1 file changed

+163
-24
lines changed

README.md

Lines changed: 163 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,169 @@
11
# Microsoft Graph CLI
22

3-
Microsoft Graph CLI SDK provides convenient methods to access Microsoft Graph capabilities using a simplistic command line interface experience on any operating system and any shell.
3+
Microsoft Graph CLI SDK provides convenient methods to access Microsoft Graph capabilities using a simplistic command line interface experience on any operating system and any shell.
44

55
## Required tools
66
A commandline tool should work on any terminal. We recommend:
77
- [Windows Terminal + version](https://apps.microsoft.com/store/detail/windows-terminal/9N0DX20HK701?hl=en-us&gl=us)
8-
- MacOS terminal
8+
- MacOS (Minimum version: 10.12 Sierra) terminal
99
- PowerShell version 7.3.2
1010

11-
## Target project requirements
12-
Download the CLI SDK to get started for
11+
## Installation
12+
Download the CLI SDK to get started for
1313
Windows, Mac, or Linux here on the assets link of the latest release: [CLI SDK Download](https://github.com/microsoftgraph/msgraph-cli/releases)
1414

1515

16+
### Windows
17+
1. Extract downloaded CLI tool for Windows to folder
18+
2. Execute program using **mgc** (on Windows CMD) or **./mgc** (on Windows PowerShell) command.
19+
20+
21+
#### Windows environment setup (Optional)
22+
23+
To allow executing the mgc command without prefixing it with `./`, you can add the executable's directory to the OS Path environment variable.
24+
On Windows PowerShell, you can add the current directory to the path by running:
25+
26+
```powershell
27+
$env:Path += ";$(pwd)`
28+
```
29+
30+
On CMD, the command becomes:
31+
```cmd
32+
set PATH=%PATH%;%cd%
33+
```
34+
35+
Though adding the current directory to the path doesn't change how you run mgc on CMD, it allows you to switch the directory you're working in.
36+
This is useful for when you need to use a different directory to save files downloaded from the CLI.
37+
38+
The commands above will update your Path for the current command session, and will need to be run whenever you start a new session e.g. when opening a new window.
39+
To make the changes permanent, you can update the environment variables by using the **System properties** dialog.
40+
You can find it by either using windows search (it appears as _view advanced system settings_) in the start menu, or following the steps below:
41+
42+
1. Open the **Settings** app
43+
2. Click on **System**
44+
3. Select the **About** option. It should be the last one in the list.
45+
4. In the **About** screen, locate and click on the _Advanced system settings_ link in the **Related links** section just below the device specifications.
46+
5. Once the dialog is open, click on the **Environment Variables** button on the bottom right.
47+
6. Select the Path environment variable and click **Edit**.
48+
7. Add the directory with the CLI to the path here.
49+
50+
> The Environment Variables screen should have 2 sections that both have a Path entry. The _User variables_ section adds to the current user's path and other users' environments should remain unchanged. The _System variables_ section will make the changes for all users in the computer.
51+
52+
53+
### MacOS
54+
55+
1. Download the CLI archive for your Mac.
56+
- If you have an M1 Mac computer, download the `msgraph-cli-osx-arm64...` package.
57+
- If you have an Intel processor, download the `msgraph-cli-osx-x64...` package.
58+
2. Extract downloaded CLI tool for Mac to a folder.
59+
3. Open a terminal in the new folder
60+
4. Execute the program using **./mgc** command.
61+
62+
#### Mac environment setup (Optional)
63+
64+
If you'd like to run the CLI from any folder, you need to either update the PATH environment variable for your shell,
65+
or add a symbolic link to the CLI into a location in the PATH (e.g. /usr/bin). Adding a symbolic link will need
66+
super user rights depending on the location you choose.
67+
68+
Adding to the PATH for your current session is also an option as it is in Windows. To do this, run the following command
69+
from your terminal in the directory of the CLI:
70+
71+
```sh
72+
export PATH=$PATH:$(PWD)
73+
```
74+
75+
Adding the location permanently can be done for the current user by editing your `~/.bash-profile` file.
76+
Add the following line to your profile:
77+
78+
```sh
79+
export PATH=$PATH:[path-to-the-cli-folder]
80+
```
81+
82+
Adding a symbolic link into `/usr/bin` (not recommended) can be done with the command below:
83+
84+
```sh
85+
sudo ln -s [path-to-the-cli-folder]/mgc /usr/bin
86+
```
87+
88+
89+
### Linux
90+
91+
Download from browser OR via Curl
92+
93+
``` bash
94+
curl -LO <link> && tar -xzf <filename>
95+
```
96+
97+
#### Linux environment setup (Required)
98+
99+
The linux environment setup is similar to the Mac setup, but with one difference. For headless linux environments,
100+
there's an additional step to configure the keyring for access token encryption.
101+
102+
To set up the PATH environment variable for your current session, run the following command from your terminal
103+
in the directory of the CLI:
104+
105+
```sh
106+
export PATH=$PATH:$(PWD)
107+
```
108+
109+
Adding the location permanently can be done for the current user by editing your shell's profile file
110+
(`~/.bash-profile` or `~/.zsh-profile`) file. Add the following line to your profile:
111+
112+
```sh
113+
export PATH=$PATH:[path-to-the-cli-folder]
114+
```
115+
116+
Adding a symbolic link into `/usr/bin` (not recommended) can be done with the command below:
117+
118+
```sh
119+
sudo ln -s [path-to-the-cli-folder]/mgc /usr/bin
120+
```
121+
122+
123+
>**Note:** The following step is **Required** if your linux distribution does not have a desktop environment e.g. WSL, Docker
124+
Failure to set this up will result in authentication failures.
125+
126+
Required packages:
127+
128+
1. gnome-keyring
129+
2. dbus
130+
3. libsecret
131+
4. libcap
132+
133+
``` bash
134+
sudo apt-get install --assume-yes gnome-keyring libsecret-1-0
135+
136+
sudo setcap cap_ipc_lock=+ep $(which gnome-keyring-daemon)
137+
138+
export DBUS_SESSION_BUS_ADDRESS=$(dbus-daemon --session --fork --print-address)
139+
140+
export KEYRING_PASSWORD=any-password
141+
142+
dbus-run-session -- echo "$KEYRING_PASSWORD" | gnome-keyring-daemon --daemonize --components=secrets --unlock
143+
144+
mgc login
145+
```
146+
147+
See the [shell script](docker/init.sh) used for docker in this repository
148+
149+
### Using Docker
150+
Find docker instructions in the docker folder [here](docker)
151+
152+
## Uninstalling
153+
1. Delete the CLI installation folder
154+
2. If path enviroment variable had been set, remove it.
155+
16156
## Registering an application in Azure AD
17157

18-
> **Note:** this step is required if your client will be calling APIs that are protected by the Microsoft Identity Platform like Microsoft Graph.
158+
> **Note:** this step is **NOT** required unless your client will be calling APIs that are protected by the Microsoft Identity Platform like Microsoft Graph OR using Client Certificate authentication option.
19159
20160
Follow the instructions in [Register an application for Microsoft identity platform authentication](register-app.md) to get an application ID (also know as a client ID).
21161

22-
### Creating the client application
23-
24162
Replace `YOUR_CLIENT_ID` with the client ID from your app registration.
25163

26164
## Executing the application
27-
Navigate to your download folder and use the **mgc** command to run commands on the CLI SDK.
165+
Navigate to your download folder and use the **mgc** (on Windows/Mac) or **./mgc** (on WSL or Linux) command to run commands on the CLI SDK.
166+
28167
Add -h to your commands to view additional commands.
29168

30169
## Authenticating on the CLI tool
@@ -41,8 +180,8 @@ mgc login --client-id `YOUR_CLIENT_ID` --tenant-id `YOUR_TENANT_ID` --scopes Use
41180
```
42181

43182
### **Delegated access**
44-
**1. DeviceCode authentication strategy**
45183

184+
**1. DeviceCode authentication strategy**
46185

47186
``` bash
48187
#Using the Default authentication (which is Device Code)
@@ -51,7 +190,7 @@ mgc login
51190
OR
52191

53192
``` bash
54-
#Using the DeviceCode authentication explicitly
193+
#Using the DeviceCode authentication explicitly
55194
mgc login --strategy DeviceCode
56195
```
57196

@@ -64,29 +203,29 @@ mgc login --strategy InteractiveBrowser
64203

65204
### **App-only access**
66205
**1. Client Certificate authentication strategy**
206+
> **Note:** Registering an application is required when using Client Certificate
207+
67208
``` bash
68209
# Using Client Certificate authentication.
69210
mgc login --strategy ClientCertificate
70211
```
71-
### **Linux users**
72212

73-
>**Note:** For linux users please run the following commands before authenticating
74-
``` bash
75-
sudo apt install gnome-keyring libsecret-1-0
213+
## Permissions
214+
Add -h to your command to view information that contains documentation links with permissions
76215

77-
sudo setcap cap_ipc_lock=+ep $(which gnome-keyring-daemon)
78-
79-
export DBUS_SESSION_BUS_ADDRESS=$(dbus-daemon --session --fork --print-address)
80-
81-
export KEYRING_PASSWORD=any-password
216+
## Check logged in user
217+
You can access the logged in user's details using:
218+
```bash
219+
mgc me get
220+
```
82221

83-
dbus-run-session -- echo "$KEYRING_PASSWORD" | gnome-keyring-daemon --daemonize --components=secrets --unlock
222+
## FAQs
223+
Qn: Why am I not getting a response back after running a command?
84224

85-
mgc login
86-
```
225+
Ans:add --debug to your command
87226

88-
### Samples
89-
You can find additional samples here: [CLI SDK samples](https://github.com/microsoftgraph/msgraph-cli/tree/main/samples)
227+
## Samples
228+
You can find additional samples here (contains sample commands for CMD, PowerShell & Bash) [CLI SDK samples](https://github.com/microsoftgraph/msgraph-cli/tree/main/samples)
90229

91230

92231
> Note: This repository is for the .NET CLI. If you are looking for the Python CLI, it's been moved to the [msgraph-cli-archived](https://github.com/microsoftgraph/msgraph-cli-archived) repository

0 commit comments

Comments
 (0)