@pnp/cli-microsoft365 7.7.0-beta.7b57cf9 → 7.7.0-beta.7d3ef49

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cli/cli.js CHANGED
@@ -17,6 +17,7 @@ import { md } from '../utils/md.js';
17
17
  import { validation } from '../utils/validation.js';
18
18
  import { prompt } from '../utils/prompt.js';
19
19
  import { timings } from './timings.js';
20
+ import chalk from 'chalk';
20
21
  const require = createRequire(import.meta.url);
21
22
  const __dirname = fileURLToPath(new URL('.', import.meta.url));
22
23
  let _config;
@@ -96,7 +97,7 @@ async function execute(rawArgs) {
96
97
  parsedArgs.h ||
97
98
  parsedArgs.help) {
98
99
  if (parsedArgs.output !== 'none') {
99
- printHelp(await getHelpMode(parsedArgs));
100
+ await printHelp(await getHelpMode(parsedArgs));
100
101
  }
101
102
  return;
102
103
  }
@@ -546,13 +547,16 @@ function getFirstNonUndefinedArrayItem(arr) {
546
547
  }
547
548
  return undefined;
548
549
  }
549
- function printHelp(helpMode, exitCode = 0) {
550
+ async function printHelp(helpMode, exitCode = 0) {
550
551
  const properties = {};
551
552
  if (cli.commandToExecute) {
552
553
  properties.command = cli.commandToExecute.name;
553
554
  printCommandHelp(helpMode);
554
555
  }
555
556
  else {
557
+ if (cli.currentCommandName && !cli.commands.some(command => command.name.startsWith(cli.currentCommandName))) {
558
+ await cli.error(chalk.red(`Command '${cli.currentCommandName}' was not found. Below you can find the commands and command groups you can use. For detailed information on a command group, use 'm365 [command group] --help'.`));
559
+ }
556
560
  cli.log();
557
561
  cli.log(`CLI for Microsoft 365 v${app.packageJson().version}`);
558
562
  cli.log(`${app.packageJson().description} `);
@@ -732,7 +736,7 @@ async function closeWithError(error, args, showHelpIfEnabled = false) {
732
736
  await cli.error(errorMessage);
733
737
  if (showHelpIfEnabled &&
734
738
  await cli.getSettingWithDefaultValue(settingsNames.showHelpOnFailure, showHelpIfEnabled)) {
735
- printHelp(await getHelpMode(args.options), exitCode);
739
+ await printHelp(await getHelpMode(args.options), exitCode);
736
740
  }
737
741
  else {
738
742
  process.exit(exitCode);
@@ -875,7 +879,8 @@ export const cli = {
875
879
  const spinnerOptions = {
876
880
  text: 'Running command...',
877
881
  /* c8 ignore next 1 */
878
- stream: cli.getSettingWithDefaultValue('errorOutput', 'stderr') === 'stderr' ? process.stderr : process.stdout
882
+ stream: cli.getSettingWithDefaultValue('errorOutput', 'stderr') === 'stderr' ? process.stderr : process.stdout,
883
+ discardStdin: false
879
884
  };
880
885
  cli.spinner = ora(spinnerOptions);
881
886
  //# sourceMappingURL=cli.js.map
@@ -31,17 +31,22 @@ class EntraUserListCommand extends GraphCommand {
31
31
  async commandAction(logger, args) {
32
32
  await this.showDeprecationWarning(logger, aadCommands.USER_LIST, commands.USER_LIST);
33
33
  try {
34
+ const selectProperties = args.options.properties ? args.options.properties : 'id,displayName,mail,userPrincipalName';
35
+ const allSelectProperties = selectProperties.split(',');
36
+ const propertiesWithSlash = allSelectProperties.filter(item => item.includes('/'));
37
+ const fieldExpand = propertiesWithSlash
38
+ .map(p => `${p.split('/')[0]}($select=${p.split('/')[1]})`)
39
+ .join(',');
40
+ const expandParam = fieldExpand.length > 0 ? `&$expand=${fieldExpand}` : '';
41
+ const selectParam = allSelectProperties.filter(item => !item.includes('/'));
34
42
  let filter = '';
35
- const properties = args.options.properties ?
36
- args.options.properties.split(',').map(p => p.trim()) :
37
- ['userPrincipalName', 'displayName'];
38
43
  try {
39
44
  filter = this.getFilter(args.options);
40
45
  }
41
46
  catch (ex) {
42
47
  throw ex;
43
48
  }
44
- const url = `${this.resource}/v1.0/users?$select=${properties.join(',')}${(filter.length > 0 ? '&' + filter : '')}&$top=100`;
49
+ const url = `${this.resource}/v1.0/users?$select=${selectParam}${expandParam}${(filter.length > 0 ? '&' + filter : '')}&$top=100`;
45
50
  const users = await odata.getAllItems(url);
46
51
  await logger.log(users);
47
52
  }
@@ -52,6 +57,7 @@ class EntraUserListCommand extends GraphCommand {
52
57
  getFilter(options) {
53
58
  const filters = {};
54
59
  const excludeOptions = [
60
+ 'type',
55
61
  'properties',
56
62
  'p',
57
63
  'd',
@@ -72,7 +78,10 @@ class EntraUserListCommand extends GraphCommand {
72
78
  });
73
79
  let filter = Object.keys(filters).map(key => `startsWith(${key}, '${filters[key]}')`).join(' and ');
74
80
  if (filter.length > 0) {
75
- filter = '$filter=' + filter;
81
+ filter = `$filter=${filter}`;
82
+ }
83
+ if (options.type) {
84
+ filter += filter.length > 0 ? ` and userType eq '${options.type}'` : `$filter=userType eq '${options.type}'`;
76
85
  }
77
86
  return filter;
78
87
  }
@@ -80,11 +89,15 @@ class EntraUserListCommand extends GraphCommand {
80
89
  _EntraUserListCommand_instances = new WeakSet(), _EntraUserListCommand_initTelemetry = function _EntraUserListCommand_initTelemetry() {
81
90
  this.telemetry.push((args) => {
82
91
  Object.assign(this.telemetryProperties, {
83
- properties: args.options.properties
92
+ type: typeof args.options.type !== 'undefined',
93
+ properties: typeof args.options.properties !== 'undefined'
84
94
  });
85
95
  });
86
96
  }, _EntraUserListCommand_initOptions = function _EntraUserListCommand_initOptions() {
87
- this.options.unshift({ option: '-p, --properties [properties]' });
97
+ this.options.unshift({
98
+ option: "--type [type]",
99
+ autocomplete: ["Member", "Guest"]
100
+ }, { option: '-p, --properties [properties]' });
88
101
  };
89
102
  export default new EntraUserListCommand();
90
103
  //# sourceMappingURL=user-list.js.map
@@ -21,6 +21,9 @@ m365 aad user list [options]
21
21
  ## Options
22
22
 
23
23
  ```md definition-list
24
+ `--type [type]`
25
+ : Filter the results to only users of a given type: `Member` or `Guest`. By default, all users are listed.
26
+
24
27
  `-p, --properties [properties]`
25
28
  : Comma-separated list of properties to retrieve
26
29
  ```
@@ -29,7 +32,9 @@ m365 aad user list [options]
29
32
 
30
33
  ## Remarks
31
34
 
32
- Using the `--properties` option, you can specify a comma-separated list of user properties to retrieve from the Microsoft Graph. If you don't specify any properties, the command will retrieve user's display name and account name.
35
+ Using the `--properties` option, you can specify a comma-separated list of user properties to retrieve from the Microsoft Graph. If you don't specify any properties, the command will retrieve user's display name, account name, id, and mail.
36
+
37
+ When the `properties` option includes values with a `/`, for example: `manager/displayName`, an additional `$expand` query parameter will be included on `manager`.
33
38
 
34
39
  To filter the list of users, include additional options that match the user property that you want to filter with. For example `--displayName Patt` will return all users whose `displayName` starts with `Patt`. Multiple filters will be combined using the `and` operator.
35
40
 
@@ -37,30 +42,42 @@ Certain properties cannot be returned within a user collection. The following pr
37
42
 
38
43
  ## Examples
39
44
 
40
- List all users in the tenant
45
+ List all users in the tenant.
41
46
 
42
47
  ```sh
43
48
  m365 entra user list
44
49
  ```
45
50
 
46
- List all users in the tenant. For each one return the display name and e-mail address
51
+ List all guest users in the tenant.
52
+
53
+ ```sh
54
+ m365 entra user list --type Guest
55
+ ```
56
+
57
+ List all users in the tenant. For each one return the display name and e-mail address.
47
58
 
48
59
  ```sh
49
60
  m365 entra user list --properties "displayName,mail"
50
61
  ```
51
62
 
52
- Show users whose display name starts with _Patt_
63
+ Show users whose display name starts with _Patt_.
53
64
 
54
65
  ```sh
55
66
  m365 entra user list --displayName Patt
56
67
  ```
57
68
 
58
- Show all account managers whose display name starts with _Patt_
69
+ Show all account managers whose display name starts with _Patt_.
59
70
 
60
71
  ```sh
61
72
  m365 entra user list --displayName Patt --jobTitle 'Account manager'
62
73
  ```
63
74
 
75
+ List users from the tenant. For each one return the display name, e-mail address, and manager information.
76
+
77
+ ```sh
78
+ m365 entra user list --properties "displayName,mail,manager/*"
79
+ ```
80
+
64
81
  ## Response
65
82
 
66
83
  <Tabs>
@@ -69,8 +86,10 @@ m365 entra user list --displayName Patt --jobTitle 'Account manager'
69
86
  ```json
70
87
  [
71
88
  {
72
- "userPrincipalName": "John@contoso.onmicrosoft.com",
73
- "displayName": "John Doe"
89
+ "id": "1f5595b2-aa07-445d-9801-a45ea18160b2",
90
+ "displayName": "John Doe",
91
+ "mail": "John@contoso.onmicrosoft.com",
92
+ "userPrincipalName": "John@contoso.onmicrosoft.com"
74
93
  }
75
94
  ]
76
95
  ```
@@ -79,17 +98,17 @@ m365 entra user list --displayName Patt --jobTitle 'Account manager'
79
98
  <TabItem value="Text">
80
99
 
81
100
  ```text
82
- userPrincipalName displayName
83
- ---------------------------------------- -------------------------
84
- John@contoso.onmicrosoft.com John Doe
101
+ id displayName mail userPrincipalName
102
+ ------------------------------------ ------------------ ----------------------------------- ------------------------------------------
103
+ 1f5595b2-aa07-445d-9801-a45ea18160b2 John Doe John@contoso.onmicrosoft.com John@contoso.onmicrosoft.com
85
104
  ```
86
105
 
87
106
  </TabItem>
88
107
  <TabItem value="CSV">
89
108
 
90
109
  ```csv
91
- userPrincipalName,displayName
92
- John@contoso.onmicrosoft.com,John Doe
110
+ id,displayName,mail,userPrincipalName
111
+ 1f5595b2-aa07-445d-9801-a45ea18160b2,John Doe,John@contoso.onmicrosoft.com,John@contoso.onmicrosoft.com
93
112
  ```
94
113
 
95
114
  </TabItem>
@@ -100,12 +119,14 @@ m365 entra user list --displayName Patt --jobTitle 'Account manager'
100
119
 
101
120
  Date: 2023-06-02
102
121
 
103
- ## John Doe
122
+ ## John Doe (1f5595b2-aa07-445d-9801-a45ea18160b2)
104
123
 
105
124
  Property | Value
106
125
  ---------|-------
107
- userPrincipalName | John@contoso.onmicrosoft.com
126
+ id | 1f5595b2-aa07-445d-9801-a45ea18160b2
108
127
  displayName | John Doe
128
+ mail | John@contoso.onmicrosoft.com
129
+ userPrincipalName | John@contoso.onmicrosoft.com
109
130
  ```
110
131
 
111
132
  </TabItem>
@@ -113,4 +134,4 @@ m365 entra user list --displayName Patt --jobTitle 'Account manager'
113
134
 
114
135
  ## More information
115
136
 
116
- - Microsoft Graph User properties: [https://developer.microsoft.com/en-us/graph/docs/api-reference/v1.0/resources/user#properties](https://developer.microsoft.com/en-us/graph/docs/api-reference/v1.0/resources/user#properties)
137
+ - Microsoft Graph User properties: [https://learn.microsoft.com/graph/api/resources/user?view=graph-rest-1.0#properties](https://learn.microsoft.com/graph/api/resources/user?view=graph-rest-1.0#properties)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pnp/cli-microsoft365",
3
- "version": "7.7.0-beta.7b57cf9",
3
+ "version": "7.7.0-beta.7d3ef49",
4
4
  "description": "Manage Microsoft 365 and SharePoint Framework projects on any platform",
5
5
  "license": "MIT",
6
6
  "main": "./dist/api.js",