@pnp/cli-microsoft365 7.7.0-beta.d874bca → 7.8.0-beta.3152fc7

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.
@@ -4,7 +4,6 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
4
4
  return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
5
5
  };
6
6
  var _SpoPageAddCommand_instances, _SpoPageAddCommand_initTelemetry, _SpoPageAddCommand_initOptions, _SpoPageAddCommand_initValidators;
7
- import { cli } from '../../../../cli/cli.js';
8
7
  import request from '../../../../request.js';
9
8
  import { formatting } from '../../../../utils/formatting.js';
10
9
  import { spo } from '../../../../utils/spo.js';
@@ -12,8 +11,6 @@ import { urlUtil } from '../../../../utils/urlUtil.js';
12
11
  import { validation } from '../../../../utils/validation.js';
13
12
  import SpoCommand from '../../../base/SpoCommand.js';
14
13
  import commands from '../../commands.js';
15
- import spoFileGetCommand from '../file/file-get.js';
16
- import spoListItemSetCommand from '../listitem/listitem-set.js';
17
14
  import { Page, supportedPageLayouts, supportedPromoteAs } from './Page.js';
18
15
  class SpoPageAddCommand extends SpoCommand {
19
16
  get name() {
@@ -64,7 +61,8 @@ class SpoPageAddCommand extends SpoCommand {
64
61
  };
65
62
  const template = await request.post(requestOptions);
66
63
  itemId = template.UniqueId;
67
- const listItemId = await this.getFileListItemId(args.options.webUrl, serverRelativeFileUrl);
64
+ const file = await spo.getFileAsListItemByUrl(args.options.webUrl, serverRelativeFileUrl, logger, this.verbose);
65
+ const listItemId = file.Id;
68
66
  const pageProps = await Page.checkout(pageName, args.options.webUrl, logger, this.debug, this.verbose);
69
67
  if (pageProps) {
70
68
  pageId = pageProps.Id;
@@ -93,15 +91,11 @@ class SpoPageAddCommand extends SpoCommand {
93
91
  break;
94
92
  case 'NewsPage':
95
93
  const listItemSetOptions = {
96
- webUrl: args.options.webUrl,
97
- listUrl: listServerRelativeUrl,
98
- id: listItemId,
99
- systemUpdate: true,
100
- FirstPublishedDate: new Date().toISOString(),
101
- verbose: this.verbose,
102
- debug: this.debug
94
+ FirstPublishedDate: new Date().toISOString()
103
95
  };
104
- await cli.executeCommand(spoListItemSetCommand, { options: { ...listItemSetOptions, _: [] } });
96
+ const listUrl = urlUtil.getServerRelativePath(args.options.webUrl, listServerRelativeUrl);
97
+ const requestUrl = `${args.options.webUrl}/_api/web/GetList('${formatting.encodeQueryParameter(listUrl)}')`;
98
+ await spo.systemUpdateListItem(requestUrl, listItemId, logger, this.verbose, listItemSetOptions);
105
99
  break;
106
100
  case 'Template':
107
101
  requestOptions.url = `${args.options.webUrl}/_api/SitePages/Pages(${listItemId})/SavePageAsTemplate`;
@@ -212,18 +206,6 @@ class SpoPageAddCommand extends SpoCommand {
212
206
  this.handleRejectedODataJsonPromise(err);
213
207
  }
214
208
  }
215
- async getFileListItemId(webUrl, serverRelativeFileUrl) {
216
- const fileGetOptions = {
217
- webUrl: webUrl,
218
- url: serverRelativeFileUrl,
219
- asListItem: true,
220
- verbose: this.verbose,
221
- debug: this.debug
222
- };
223
- const fileGetOutput = await cli.executeCommandWithOutput(spoFileGetCommand, { options: { ...fileGetOptions, _: [] } });
224
- const fileGetOutputJson = JSON.parse(fileGetOutput.stdout);
225
- return fileGetOutputJson.Id;
226
- }
227
209
  }
228
210
  _SpoPageAddCommand_instances = new WeakSet(), _SpoPageAddCommand_initTelemetry = function _SpoPageAddCommand_initTelemetry() {
229
211
  this.telemetry.push((args) => {
@@ -5,7 +5,6 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
5
5
  };
6
6
  var _SpoPageSetCommand_instances, _SpoPageSetCommand_initTelemetry, _SpoPageSetCommand_initOptions, _SpoPageSetCommand_initTypes, _SpoPageSetCommand_initValidators;
7
7
  import { Auth } from '../../../../Auth.js';
8
- import { cli } from '../../../../cli/cli.js';
9
8
  import request from '../../../../request.js';
10
9
  import { formatting } from '../../../../utils/formatting.js';
11
10
  import { spo } from '../../../../utils/spo.js';
@@ -13,8 +12,6 @@ import { urlUtil } from '../../../../utils/urlUtil.js';
13
12
  import { validation } from '../../../../utils/validation.js';
14
13
  import SpoCommand from '../../../base/SpoCommand.js';
15
14
  import commands from '../../commands.js';
16
- import spoFileGetCommand from '../file/file-get.js';
17
- import spoListItemSetCommand from '../listitem/listitem-set.js';
18
15
  import { Page, supportedPageLayouts, supportedPromoteAs } from './Page.js';
19
16
  class SpoPageSetCommand extends SpoCommand {
20
17
  get name() {
@@ -49,6 +46,8 @@ class SpoPageSetCommand extends SpoCommand {
49
46
  }
50
47
  const listServerRelativeUrl = `${urlUtil.getServerRelativeSiteUrl(args.options.webUrl)}/sitepages`;
51
48
  const serverRelativeFileUrl = `${listServerRelativeUrl}/${pageName}`;
49
+ const listUrl = urlUtil.getServerRelativePath(args.options.webUrl, listServerRelativeUrl);
50
+ const requestUrl = `${args.options.webUrl}/_api/web/GetList('${formatting.encodeQueryParameter(listUrl)}')`;
52
51
  const needsToSavePage = !!args.options.title || !!args.options.description;
53
52
  try {
54
53
  const requestDigestResult = await spo.getRequestDigest(args.options.webUrl);
@@ -65,21 +64,16 @@ class SpoPageSetCommand extends SpoCommand {
65
64
  authorByline = page.AuthorByline;
66
65
  }
67
66
  if (args.options.layoutType) {
68
- const itemId = await this.getFileListItemId(args.options.webUrl, serverRelativeFileUrl);
67
+ const file = await spo.getFileAsListItemByUrl(args.options.webUrl, serverRelativeFileUrl, logger, this.verbose);
68
+ const itemId = file.Id;
69
69
  const listItemSetOptions = {
70
- webUrl: args.options.webUrl,
71
- listUrl: listServerRelativeUrl,
72
- id: itemId,
73
- systemUpdate: true,
74
- PageLayoutType: args.options.layoutType,
75
- verbose: this.verbose,
76
- debug: this.debug
70
+ PageLayoutType: args.options.layoutType
77
71
  };
78
72
  if (args.options.layoutType === 'Article') {
79
73
  listItemSetOptions.PromotedState = 0;
80
74
  listItemSetOptions.BannerImageUrl = `${resource}/_layouts/15/images/sitepagethumbnail.png, /_layouts/15/images/sitepagethumbnail.png`;
81
75
  }
82
- await cli.executeCommand(spoListItemSetCommand, { options: { ...listItemSetOptions, _: [] } });
76
+ await spo.systemUpdateListItem(requestUrl, itemId, logger, this.verbose, listItemSetOptions);
83
77
  }
84
78
  if (args.options.promoteAs) {
85
79
  const requestOptions = {
@@ -101,21 +95,17 @@ class SpoPageSetCommand extends SpoCommand {
101
95
  await request.post(requestOptions);
102
96
  break;
103
97
  case 'NewsPage':
104
- const newsPageItemId = await this.getFileListItemId(args.options.webUrl, serverRelativeFileUrl);
98
+ const newsPageItem = await spo.getFileAsListItemByUrl(args.options.webUrl, serverRelativeFileUrl, logger, this.verbose);
99
+ const newsPageItemId = newsPageItem.Id;
105
100
  const listItemSetOptions = {
106
- webUrl: args.options.webUrl,
107
- listUrl: listServerRelativeUrl,
108
- id: newsPageItemId,
109
- systemUpdate: true,
110
101
  PromotedState: 2,
111
- FirstPublishedDate: new Date().toISOString(),
112
- verbose: this.verbose,
113
- debug: this.debug
102
+ FirstPublishedDate: new Date().toISOString()
114
103
  };
115
- await cli.executeCommand(spoListItemSetCommand, { options: { ...listItemSetOptions, _: [] } });
104
+ await spo.systemUpdateListItem(requestUrl, newsPageItemId, logger, this.verbose, listItemSetOptions);
116
105
  break;
117
106
  case 'Template':
118
- const templateItemId = await this.getFileListItemId(args.options.webUrl, serverRelativeFileUrl);
107
+ const templateItem = await spo.getFileAsListItemByUrl(args.options.webUrl, serverRelativeFileUrl, logger, this.verbose);
108
+ const templateItemId = templateItem.Id;
119
109
  requestOptions.headers = {
120
110
  'X-RequestDigest': requestDigest,
121
111
  'content-type': 'application/json;odata=nometadata',
@@ -210,17 +200,12 @@ class SpoPageSetCommand extends SpoCommand {
210
200
  await request.post(requestOptions);
211
201
  }
212
202
  if (args.options.demoteFrom === 'NewsPage') {
213
- const fileId = await this.getFileListItemId(args.options.webUrl, serverRelativeFileUrl);
203
+ const file = await spo.getFileAsListItemByUrl(args.options.webUrl, serverRelativeFileUrl, logger, this.verbose);
204
+ const fileId = file.Id;
214
205
  const listItemSetOptions = {
215
- webUrl: args.options.webUrl,
216
- listUrl: listServerRelativeUrl,
217
- id: fileId,
218
- systemUpdate: true,
219
- PromotedState: 0,
220
- verbose: this.verbose,
221
- debug: this.debug
206
+ PromotedState: 0
222
207
  };
223
- await cli.executeCommandWithOutput(spoListItemSetCommand, { options: { ...listItemSetOptions, _: [] } });
208
+ await spo.systemUpdateListItem(requestUrl, fileId, logger, this.verbose, listItemSetOptions);
224
209
  }
225
210
  let requestOptions;
226
211
  if (!args.options.publish) {
@@ -254,18 +239,6 @@ class SpoPageSetCommand extends SpoCommand {
254
239
  this.handleRejectedODataJsonPromise(err);
255
240
  }
256
241
  }
257
- async getFileListItemId(webUrl, serverRelativeFileUrl) {
258
- const fileGetOptions = {
259
- webUrl: webUrl,
260
- url: serverRelativeFileUrl,
261
- asListItem: true,
262
- verbose: this.verbose,
263
- debug: this.debug
264
- };
265
- const fileGetOutput = await cli.executeCommandWithOutput(spoFileGetCommand, { options: { ...fileGetOptions, _: [] } });
266
- const fileGetOutputJson = JSON.parse(fileGetOutput.stdout);
267
- return fileGetOutputJson.Id;
268
- }
269
242
  }
270
243
  _SpoPageSetCommand_instances = new WeakSet(), _SpoPageSetCommand_initTelemetry = function _SpoPageSetCommand_initTelemetry() {
271
244
  this.telemetry.push((args) => {
@@ -15,7 +15,7 @@ class SpoSiteAppPermissionRemoveCommand extends GraphCommand {
15
15
  return commands.SITE_APPPERMISSION_REMOVE;
16
16
  }
17
17
  get description() {
18
- return 'Removes an application permission from the site';
18
+ return 'Removes a specific application permission from a site';
19
19
  }
20
20
  constructor() {
21
21
  super();
@@ -48,7 +48,7 @@ class SpoSiteAppPermissionRemoveCommand extends GraphCommand {
48
48
  }
49
49
  async getPermissionIds(siteId, options) {
50
50
  if (options.id) {
51
- return Promise.resolve([options.id]);
51
+ return [options.id];
52
52
  }
53
53
  const permissionsObject = await this.getPermissions(siteId);
54
54
  let permissions = permissionsObject.value;
@@ -61,7 +61,7 @@ class SpoSiteAppPermissionRemoveCommand extends GraphCommand {
61
61
  const spRequestOptions = {
62
62
  url: `${this.resource}/v1.0/sites/${siteId}/permissions/${permissionId}`,
63
63
  headers: {
64
- 'accept': 'application/json;odata.metadata=none'
64
+ accept: 'application/json;odata.metadata=none'
65
65
  },
66
66
  responseType: 'json'
67
67
  };
@@ -69,16 +69,16 @@ class SpoSiteAppPermissionRemoveCommand extends GraphCommand {
69
69
  }
70
70
  async commandAction(logger, args) {
71
71
  if (args.options.force) {
72
- await this.removeSiteAppPermission(logger, args.options);
72
+ await this.removeSiteAppPermission(args.options);
73
73
  }
74
74
  else {
75
75
  const result = await cli.promptForConfirmation({ message: `Are you sure you want to remove the specified application permission from site ${args.options.siteUrl}?` });
76
76
  if (result) {
77
- await this.removeSiteAppPermission(logger, args.options);
77
+ await this.removeSiteAppPermission(args.options);
78
78
  }
79
79
  }
80
80
  }
81
- async removeSiteAppPermission(logger, options) {
81
+ async removeSiteAppPermission(options) {
82
82
  try {
83
83
  const siteId = await spo.getSpoGraphSiteId(options.siteUrl);
84
84
  const permissionIdsToRemove = await this.getPermissionIds(siteId, options);
@@ -86,8 +86,7 @@ class SpoSiteAppPermissionRemoveCommand extends GraphCommand {
86
86
  for (const permissionId of permissionIdsToRemove) {
87
87
  tasks.push(this.removePermissions(siteId, permissionId));
88
88
  }
89
- const response = await Promise.all(tasks);
90
- await logger.log(response);
89
+ await Promise.all(tasks);
91
90
  }
92
91
  catch (err) {
93
92
  this.handleRejectedODataJsonPromise(err);
@@ -100,7 +99,7 @@ _SpoSiteAppPermissionRemoveCommand_instances = new WeakSet(), _SpoSiteAppPermiss
100
99
  appId: typeof args.options.appId !== 'undefined',
101
100
  appDisplayName: typeof args.options.appDisplayName !== 'undefined',
102
101
  id: typeof args.options.id !== 'undefined',
103
- force: (!!args.options.force).toString()
102
+ force: !!args.options.force
104
103
  });
105
104
  });
106
105
  }, _SpoSiteAppPermissionRemoveCommand_initOptions = function _SpoSiteAppPermissionRemoveCommand_initOptions() {
@@ -3,6 +3,8 @@ import { cli } from '../cli/cli.js';
3
3
  let inquirerInput;
4
4
  let inquirerConfirm;
5
5
  let inquirerSelect;
6
+ ;
7
+ ;
6
8
  export const prompt = {
7
9
  /* c8 ignore next 9 */
8
10
  async forInput(config) {
package/dist/utils/spo.js CHANGED
@@ -1,3 +1,4 @@
1
+ import os from 'os';
1
2
  import url from 'url';
2
3
  import { urlUtil } from "./urlUtil.js";
3
4
  import { validation } from "./validation.js";
@@ -1231,6 +1232,113 @@ export const spo = {
1231
1232
  };
1232
1233
  await request.post(requestOptions);
1233
1234
  },
1235
+ /**
1236
+ * Gets a file as list item by url
1237
+ * @param absoluteListUrl The absolute url to the list
1238
+ * @param url The url of the file
1239
+ * @param logger The logger object
1240
+ * @param verbose If in verbose mode
1241
+ * @returns The list item object
1242
+ */
1243
+ async getFileAsListItemByUrl(absoluteListUrl, url, logger, verbose) {
1244
+ if (verbose && logger) {
1245
+ logger.logToStderr(`Getting the file properties with url ${url}`);
1246
+ }
1247
+ const serverRelativePath = urlUtil.getServerRelativePath(absoluteListUrl, url);
1248
+ const requestUrl = `${absoluteListUrl}/_api/web/GetFileByServerRelativePath(DecodedUrl=@f)?$expand=ListItemAllFields&@f='${formatting.encodeQueryParameter(serverRelativePath)}'`;
1249
+ const requestOptions = {
1250
+ url: requestUrl,
1251
+ headers: {
1252
+ 'accept': 'application/json;odata=nometadata'
1253
+ },
1254
+ responseType: 'json'
1255
+ };
1256
+ const file = await request.get(requestOptions);
1257
+ return file.ListItemAllFields;
1258
+ },
1259
+ /**
1260
+ * Updates a list item with system update
1261
+ * @param absoluteListUrl The absolute base URL without query parameters, pointing to the specific list where the item resides. This URL should represent the list.
1262
+ * @param itemId The id of the list item
1263
+ * @param properties An object of the properties that should be updated
1264
+ * @param contentTypeName The name of the content type to update
1265
+ * @param logger The logger object
1266
+ * @param verbose If in verbose mode
1267
+ * @returns The updated list item object
1268
+ */
1269
+ async systemUpdateListItem(absoluteListUrl, itemId, logger, verbose, properties, contentTypeName) {
1270
+ if (!properties && !contentTypeName) {
1271
+ // Neither properties nor contentTypeName provided, no need to proceed
1272
+ throw 'Either properties or contentTypeName must be provided for systemUpdateListItem.';
1273
+ }
1274
+ const parsedUrl = new URL(absoluteListUrl);
1275
+ const serverRelativeSiteMatch = absoluteListUrl.match(new RegExp('/sites/[^/]+'));
1276
+ const webUrl = `${parsedUrl.protocol}//${parsedUrl.host}${serverRelativeSiteMatch ?? ''}`;
1277
+ if (verbose && logger) {
1278
+ logger.logToStderr(`Getting list id...`);
1279
+ }
1280
+ const listRequestOptions = {
1281
+ url: `${absoluteListUrl}?$select=Id`,
1282
+ headers: {
1283
+ 'accept': 'application/json;odata=nometadata'
1284
+ },
1285
+ responseType: 'json'
1286
+ };
1287
+ const list = await request.get(listRequestOptions);
1288
+ const listId = list.Id;
1289
+ if (verbose && logger) {
1290
+ logger.logToStderr(`Getting request digest for systemUpdate request`);
1291
+ }
1292
+ const res = await spo.getRequestDigest(webUrl);
1293
+ const formDigestValue = res.FormDigestValue;
1294
+ const objectIdentity = await spo.requestObjectIdentity(webUrl, logger, verbose);
1295
+ let index = 0;
1296
+ const requestBodyOptions = properties ? Object.keys(properties).map(key => `
1297
+ <Method Name="ParseAndSetFieldValue" Id="${++index}" ObjectPathId="147">
1298
+ <Parameters>
1299
+ <Parameter Type="String">${key}</Parameter>
1300
+ <Parameter Type="String">${properties[key].toString()}</Parameter>
1301
+ </Parameters>
1302
+ </Method>`) : [];
1303
+ const additionalContentType = contentTypeName ? `
1304
+ <Method Name="ParseAndSetFieldValue" Id="${++index}" ObjectPathId="147">
1305
+ <Parameters>
1306
+ <Parameter Type="String">ContentType</Parameter>
1307
+ <Parameter Type="String">${contentTypeName}</Parameter>
1308
+ </Parameters>
1309
+ </Method>` : '';
1310
+ const requestBody = `<Request AddExpandoFieldTypeSuffix="true" SchemaVersion="15.0.0.0" LibraryVersion="16.0.0.0" ApplicationName="${config.applicationName}" xmlns="http://schemas.microsoft.com/sharepoint/clientquery/2009">
1311
+ <Actions>
1312
+ ${requestBodyOptions.join('')}${additionalContentType}
1313
+ <Method Name="SystemUpdate" Id="${++index}" ObjectPathId="147" />
1314
+ </Actions>
1315
+ <ObjectPaths>
1316
+ <Identity Id="147" Name="${objectIdentity}:list:${listId}:item:${itemId},1" />
1317
+ </ObjectPaths>
1318
+ </Request>`;
1319
+ const requestOptions = {
1320
+ url: `${webUrl}/_vti_bin/client.svc/ProcessQuery`,
1321
+ headers: {
1322
+ 'Content-Type': 'text/xml',
1323
+ 'X-RequestDigest': formDigestValue
1324
+ },
1325
+ data: requestBody
1326
+ };
1327
+ const response = await request.post(requestOptions);
1328
+ if (response.indexOf("ErrorMessage") > -1) {
1329
+ throw `Error occurred in systemUpdate operation - ${response}`;
1330
+ }
1331
+ const id = Number(itemId);
1332
+ const requestOptionsItems = {
1333
+ url: `${absoluteListUrl}/items(${id})`,
1334
+ headers: {
1335
+ 'accept': 'application/json;odata=nometadata'
1336
+ },
1337
+ responseType: 'json'
1338
+ };
1339
+ const itemsResponse = await request.get(requestOptionsItems);
1340
+ return (itemsResponse);
1341
+ },
1234
1342
  /**
1235
1343
  * Removes the retention label from the items in the given list.
1236
1344
  * @param webUrl The url of the web
@@ -1334,6 +1442,86 @@ export const spo = {
1334
1442
  };
1335
1443
  const site = await request.get(requestOptions);
1336
1444
  return site.id;
1445
+ },
1446
+ /**
1447
+ * Retrieves the ObjectIdentity from a SharePoint site
1448
+ * @param webUrl web url
1449
+ * @param logger The logger object
1450
+ * @param verbose If in verbose mode
1451
+ * @return The ObjectIdentity as string
1452
+ */
1453
+ async requestObjectIdentity(webUrl, logger, verbose) {
1454
+ const res = await spo.getRequestDigest(webUrl);
1455
+ const formDigestValue = res.FormDigestValue;
1456
+ const requestOptions = {
1457
+ url: `${webUrl}/_vti_bin/client.svc/ProcessQuery`,
1458
+ headers: {
1459
+ 'X-RequestDigest': formDigestValue
1460
+ },
1461
+ data: `<Request AddExpandoFieldTypeSuffix="true" SchemaVersion="15.0.0.0" LibraryVersion="16.0.0.0" ApplicationName="${config.applicationName}" xmlns="http://schemas.microsoft.com/sharepoint/clientquery/2009"><Actions><Query Id="1" ObjectPathId="5"><Query SelectAllProperties="false"><Properties><Property Name="ServerRelativeUrl" ScalarProperty="true" /></Properties></Query></Query></Actions><ObjectPaths><Property Id="5" ParentId="3" Name="Web" /><StaticProperty Id="3" TypeId="{3747adcd-a3c3-41b9-bfab-4a64dd2f1e0a}" Name="Current" /></ObjectPaths></Request>`
1462
+ };
1463
+ const response = await request.post(requestOptions);
1464
+ if (verbose) {
1465
+ logger.logToStderr('Attempt to get _ObjectIdentity_ key values');
1466
+ }
1467
+ const json = JSON.parse(response);
1468
+ const contents = json.find(x => { return x.ErrorInfo; });
1469
+ if (contents && contents.ErrorInfo) {
1470
+ throw contents.ErrorInfo.ErrorMessage || 'ClientSvc unknown error';
1471
+ }
1472
+ const identityObject = json.find(x => { return x._ObjectIdentity_; });
1473
+ if (identityObject) {
1474
+ return identityObject._ObjectIdentity_;
1475
+ }
1476
+ throw 'Cannot proceed. _ObjectIdentity_ not found'; // this is not supposed to happen
1477
+ },
1478
+ /**
1479
+ * Updates a list item without system update
1480
+ * @param absoluteListUrl The absolute base URL without query parameters, pointing to the specific list where the item resides. This URL should represent the list.
1481
+ * @param itemId The id of the list item
1482
+ * @param properties An object of the properties that should be updated
1483
+ * @param contentTypeName The name of the content type to update
1484
+ * @returns The updated listitem object
1485
+ */
1486
+ async updateListItem(absoluteListUrl, itemId, properties, contentTypeName) {
1487
+ const requestBodyOptions = [
1488
+ ...(properties
1489
+ ? Object.keys(properties).map((key) => ({
1490
+ FieldName: key,
1491
+ FieldValue: properties[key].toString()
1492
+ }))
1493
+ : [])
1494
+ ];
1495
+ const requestBody = {
1496
+ formValues: requestBodyOptions
1497
+ };
1498
+ contentTypeName && requestBody.formValues.push({
1499
+ FieldName: 'ContentType',
1500
+ FieldValue: contentTypeName
1501
+ });
1502
+ const requestOptions = {
1503
+ url: `${absoluteListUrl}/items(${itemId})/ValidateUpdateListItem()`,
1504
+ headers: {
1505
+ 'accept': 'application/json;odata=nometadata'
1506
+ },
1507
+ data: requestBody,
1508
+ responseType: 'json'
1509
+ };
1510
+ const response = await request.post(requestOptions);
1511
+ // Response is from /ValidateUpdateListItem POST call, perform get on updated item to get all field values
1512
+ const fieldValues = response.value;
1513
+ if (fieldValues.some(f => f.HasException)) {
1514
+ throw `Updating the items has failed with the following errors: ${os.EOL}${fieldValues.filter(f => f.HasException).map(f => { return `- ${f.FieldName} - ${f.ErrorMessage}`; }).join(os.EOL)}`;
1515
+ }
1516
+ const requestOptionsItems = {
1517
+ url: `${absoluteListUrl}/items(${itemId})`,
1518
+ headers: {
1519
+ 'accept': 'application/json;odata=nometadata'
1520
+ },
1521
+ responseType: 'json'
1522
+ };
1523
+ const itemsResponse = await request.get(requestOptionsItems);
1524
+ return (itemsResponse);
1337
1525
  }
1338
1526
  };
1339
1527
  //# sourceMappingURL=spo.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)