@pnp/cli-microsoft365 7.4.0-beta.ae3d33b → 7.4.0-beta.b16adf9
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.
|
@@ -3,7 +3,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
3
3
|
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
4
4
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
5
5
|
};
|
|
6
|
-
var _AadM365GroupUserListCommand_instances, _AadM365GroupUserListCommand_initTelemetry, _AadM365GroupUserListCommand_initOptions, _AadM365GroupUserListCommand_initValidators;
|
|
6
|
+
var _AadM365GroupUserListCommand_instances, _AadM365GroupUserListCommand_initTelemetry, _AadM365GroupUserListCommand_initOptions, _AadM365GroupUserListCommand_initOptionSets, _AadM365GroupUserListCommand_initValidators;
|
|
7
7
|
import { odata } from '../../../../utils/odata.js';
|
|
8
8
|
import { validation } from '../../../../utils/validation.js';
|
|
9
9
|
import GraphCommand from '../../../base/GraphCommand.js';
|
|
@@ -21,18 +21,35 @@ class AadM365GroupUserListCommand extends GraphCommand {
|
|
|
21
21
|
_AadM365GroupUserListCommand_instances.add(this);
|
|
22
22
|
__classPrivateFieldGet(this, _AadM365GroupUserListCommand_instances, "m", _AadM365GroupUserListCommand_initTelemetry).call(this);
|
|
23
23
|
__classPrivateFieldGet(this, _AadM365GroupUserListCommand_instances, "m", _AadM365GroupUserListCommand_initOptions).call(this);
|
|
24
|
+
__classPrivateFieldGet(this, _AadM365GroupUserListCommand_instances, "m", _AadM365GroupUserListCommand_initOptionSets).call(this);
|
|
24
25
|
__classPrivateFieldGet(this, _AadM365GroupUserListCommand_instances, "m", _AadM365GroupUserListCommand_initValidators).call(this);
|
|
25
26
|
}
|
|
26
27
|
async commandAction(logger, args) {
|
|
27
28
|
try {
|
|
28
|
-
|
|
29
|
+
if (args.options.role === 'Guest') {
|
|
30
|
+
this.warn(logger, `Value 'Guest' for the option role is deprecated. Use --filter "userType eq 'Guest'" instead.`);
|
|
31
|
+
}
|
|
32
|
+
const groupId = await this.getGroupId(args.options, logger);
|
|
33
|
+
const isUnifiedGroup = await aadGroup.isUnifiedGroup(groupId);
|
|
29
34
|
if (!isUnifiedGroup) {
|
|
30
|
-
throw Error(`Specified group
|
|
35
|
+
throw Error(`Specified group '${args.options.groupId || args.options.groupDisplayName}' is not a Microsoft 365 group.`);
|
|
36
|
+
}
|
|
37
|
+
let users = [];
|
|
38
|
+
if (!args.options.role || args.options.role === 'Owner') {
|
|
39
|
+
const owners = await this.getUsers(args.options, 'Owners', groupId, logger);
|
|
40
|
+
owners.forEach(owner => users.push({ ...owner, roles: ['Owner'], userType: 'Owner' }));
|
|
31
41
|
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
42
|
+
if (!args.options.role || args.options.role === 'Member' || args.options.role === 'Guest') {
|
|
43
|
+
const members = await this.getUsers(args.options, 'Members', groupId, logger);
|
|
44
|
+
members.forEach((member) => {
|
|
45
|
+
const user = users.find((u) => u.id === member.id);
|
|
46
|
+
if (user !== undefined) {
|
|
47
|
+
user.roles.push('Member');
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
users.push({ ...member, roles: ['Member'] });
|
|
51
|
+
}
|
|
52
|
+
});
|
|
36
53
|
}
|
|
37
54
|
if (args.options.role) {
|
|
38
55
|
users = users.filter(i => i.userType === args.options.role);
|
|
@@ -43,43 +60,82 @@ class AadM365GroupUserListCommand extends GraphCommand {
|
|
|
43
60
|
this.handleRejectedODataJsonPromise(err);
|
|
44
61
|
}
|
|
45
62
|
}
|
|
46
|
-
async
|
|
63
|
+
async getGroupId(options, logger) {
|
|
64
|
+
if (options.groupId) {
|
|
65
|
+
return options.groupId;
|
|
66
|
+
}
|
|
47
67
|
if (this.verbose) {
|
|
48
|
-
await logger.logToStderr(
|
|
68
|
+
await logger.logToStderr('Retrieving Group Id...');
|
|
49
69
|
}
|
|
50
|
-
|
|
51
|
-
const users = await odata.getAllItems(endpoint);
|
|
52
|
-
// Currently there is a bug in the Microsoft Graph that returns Owners as
|
|
53
|
-
// userType 'member'. We therefore update all returned user as owner
|
|
54
|
-
users.forEach(user => {
|
|
55
|
-
user.userType = 'Owner';
|
|
56
|
-
});
|
|
57
|
-
return users;
|
|
70
|
+
return await aadGroup.getGroupIdByDisplayName(options.groupDisplayName);
|
|
58
71
|
}
|
|
59
|
-
async
|
|
72
|
+
async getUsers(options, role, groupId, logger) {
|
|
73
|
+
const { properties, filter } = options;
|
|
60
74
|
if (this.verbose) {
|
|
61
|
-
await logger.logToStderr(`Retrieving
|
|
75
|
+
await logger.logToStderr(`Retrieving ${role} of the group with id ${groupId}`);
|
|
76
|
+
}
|
|
77
|
+
const selectProperties = properties ?
|
|
78
|
+
`${properties.split(',').filter(f => f.toLowerCase() !== 'id').concat('id').map(p => p.trim()).join(',')}` :
|
|
79
|
+
'id,displayName,userPrincipalName,givenName,surname,userType';
|
|
80
|
+
const allSelectProperties = selectProperties.split(',');
|
|
81
|
+
const propertiesWithSlash = allSelectProperties.filter(item => item.includes('/'));
|
|
82
|
+
const fieldsToExpand = [];
|
|
83
|
+
propertiesWithSlash.forEach(p => {
|
|
84
|
+
const propertiesSplit = p.split('/');
|
|
85
|
+
fieldsToExpand.push(`${propertiesSplit[0]}($select=${propertiesSplit[1]})`);
|
|
86
|
+
});
|
|
87
|
+
const fieldExpand = fieldsToExpand.join(',');
|
|
88
|
+
const expandParam = fieldExpand.length > 0 ? `&$expand=${fieldExpand}` : '';
|
|
89
|
+
const selectParam = allSelectProperties.filter(item => !item.includes('/'));
|
|
90
|
+
const endpoint = `${this.resource}/v1.0/groups/${groupId}/${role}/microsoft.graph.user?$select=${selectParam}${expandParam}`;
|
|
91
|
+
if (filter) {
|
|
92
|
+
// While using the filter, we need to specify the ConsistencyLevel header.
|
|
93
|
+
// Can be refactored when the header is no longer necessary.
|
|
94
|
+
const requestOptions = {
|
|
95
|
+
url: `${endpoint}&$filter=${encodeURIComponent(filter)}&$count=true`,
|
|
96
|
+
headers: {
|
|
97
|
+
accept: 'application/json;odata.metadata=none',
|
|
98
|
+
ConsistencyLevel: 'eventual'
|
|
99
|
+
},
|
|
100
|
+
responseType: 'json'
|
|
101
|
+
};
|
|
102
|
+
return await odata.getAllItems(requestOptions);
|
|
103
|
+
}
|
|
104
|
+
else {
|
|
105
|
+
return await odata.getAllItems(endpoint);
|
|
62
106
|
}
|
|
63
|
-
const endpoint = `${this.resource}/v1.0/groups/${groupId}/members?$select=id,displayName,userPrincipalName,userType`;
|
|
64
|
-
return await odata.getAllItems(endpoint);
|
|
65
107
|
}
|
|
66
108
|
}
|
|
67
109
|
_AadM365GroupUserListCommand_instances = new WeakSet(), _AadM365GroupUserListCommand_initTelemetry = function _AadM365GroupUserListCommand_initTelemetry() {
|
|
68
110
|
this.telemetry.push((args) => {
|
|
69
111
|
Object.assign(this.telemetryProperties, {
|
|
70
|
-
|
|
112
|
+
groupId: typeof args.options.groupId !== 'undefined',
|
|
113
|
+
groupDisplayName: typeof args.options.groupDisplayName !== 'undefined',
|
|
114
|
+
role: typeof args.options.role !== 'undefined',
|
|
115
|
+
properties: typeof args.options.properties !== 'undefined',
|
|
116
|
+
filter: typeof args.options.filter !== 'undefined'
|
|
71
117
|
});
|
|
72
118
|
});
|
|
73
119
|
}, _AadM365GroupUserListCommand_initOptions = function _AadM365GroupUserListCommand_initOptions() {
|
|
74
120
|
this.options.unshift({
|
|
75
|
-
option: "-i, --groupId
|
|
121
|
+
option: "-i, --groupId [groupId]"
|
|
122
|
+
}, {
|
|
123
|
+
option: "-n, --groupDisplayName [groupDisplayName]"
|
|
76
124
|
}, {
|
|
77
125
|
option: "-r, --role [type]",
|
|
78
126
|
autocomplete: ["Owner", "Member", "Guest"]
|
|
127
|
+
}, {
|
|
128
|
+
option: "-p, --properties [properties]"
|
|
129
|
+
}, {
|
|
130
|
+
option: "-f, --filter [filter]"
|
|
131
|
+
});
|
|
132
|
+
}, _AadM365GroupUserListCommand_initOptionSets = function _AadM365GroupUserListCommand_initOptionSets() {
|
|
133
|
+
this.optionSets.push({
|
|
134
|
+
options: ['groupId', 'groupDisplayName']
|
|
79
135
|
});
|
|
80
136
|
}, _AadM365GroupUserListCommand_initValidators = function _AadM365GroupUserListCommand_initValidators() {
|
|
81
137
|
this.validators.push(async (args) => {
|
|
82
|
-
if (!validation.isValidGuid(args.options.groupId)) {
|
|
138
|
+
if (args.options.groupId && !validation.isValidGuid(args.options.groupId)) {
|
|
83
139
|
return `${args.options.groupId} is not a valid GUID`;
|
|
84
140
|
}
|
|
85
141
|
if (args.options.role) {
|
|
@@ -15,33 +15,52 @@ m365 aad m365group user list [options]
|
|
|
15
15
|
## Options
|
|
16
16
|
|
|
17
17
|
```md definition-list
|
|
18
|
-
`-i, --groupId
|
|
19
|
-
: The ID of the Microsoft 365 group
|
|
18
|
+
`-i, --groupId [groupId]`
|
|
19
|
+
: The ID of the Microsoft 365 group. Specify `groupId` or `groupDisplayName` but not both.
|
|
20
|
+
|
|
21
|
+
`-n, --groupDisplayName [groupDisplayName]`
|
|
22
|
+
: The display name of the Microsoft 365 group. Specify `groupId` or `groupDisplayName` but not both.
|
|
20
23
|
|
|
21
24
|
`-r, --role [role]`
|
|
22
|
-
: Filter the results to only users with the given role: `Owner`, `Member`, `Guest
|
|
25
|
+
: Filter the results to only users with the given role. Allowed values: `Owner`, `Member`, or (Deprecated) `Guest`.
|
|
26
|
+
|
|
27
|
+
`-p, --properties [properties]`
|
|
28
|
+
: Comma-separated list of properties to retrieve.
|
|
29
|
+
|
|
30
|
+
`-f, --filter [filter]`
|
|
31
|
+
: OData filter to use to query the list of users with.
|
|
23
32
|
```
|
|
24
33
|
|
|
25
34
|
<Global />
|
|
26
35
|
|
|
36
|
+
## Remarks
|
|
37
|
+
|
|
38
|
+
When the `properties` option includes values with a `/`, for example: `manager/displayName`, an additional `$expand` query parameter will be included on `manager`.
|
|
39
|
+
|
|
27
40
|
## Examples
|
|
28
41
|
|
|
29
|
-
List all users and their role
|
|
42
|
+
List all users and their role from Microsoft 365 group specified by ID.
|
|
30
43
|
|
|
31
44
|
```sh
|
|
32
|
-
m365 aad m365group user list --groupId
|
|
45
|
+
m365 aad m365group user list --groupId 00000000-0000-0000-0000-000000000000
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
List all owners from Microsoft 365 group specified by display name.
|
|
49
|
+
|
|
50
|
+
```
|
|
51
|
+
m365 aad m365group user list --groupDisplayName Developers --role Owner
|
|
33
52
|
```
|
|
34
53
|
|
|
35
|
-
List all
|
|
54
|
+
List specific properties for all group users from a group specified by ID.
|
|
36
55
|
|
|
37
56
|
```sh
|
|
38
|
-
m365 aad m365group user list --groupId
|
|
57
|
+
m365 aad m365group user list --groupId 03cba9da-3974-46c1-afaf-79caa2e45bbe --properties "id,jobTitle,companyName,accountEnabled"
|
|
39
58
|
```
|
|
40
59
|
|
|
41
|
-
|
|
60
|
+
List all group members that are guest users.
|
|
42
61
|
|
|
43
62
|
```sh
|
|
44
|
-
m365 aad m365group user list --
|
|
63
|
+
m365 aad m365group user list --groupDisplayName Developers --filter "userType eq 'Guest'"
|
|
45
64
|
```
|
|
46
65
|
|
|
47
66
|
## Response
|
|
@@ -55,7 +74,12 @@ m365 aad m365group user list --groupId '00000000-0000-0000-0000-000000000000' --
|
|
|
55
74
|
"id": "da52218e-4822-4ac6-b41d-255e2059655e",
|
|
56
75
|
"displayName": "Adele Vance",
|
|
57
76
|
"userPrincipalName": "AdeleV@contoso.OnMicrosoft.com",
|
|
58
|
-
"
|
|
77
|
+
"givenName": "Adele",
|
|
78
|
+
"surname": "Vance",
|
|
79
|
+
"roles": [
|
|
80
|
+
"Owner",
|
|
81
|
+
"Member"
|
|
82
|
+
]
|
|
59
83
|
}
|
|
60
84
|
]
|
|
61
85
|
```
|
|
@@ -64,17 +88,17 @@ m365 aad m365group user list --groupId '00000000-0000-0000-0000-000000000000' --
|
|
|
64
88
|
<TabItem value="Text">
|
|
65
89
|
|
|
66
90
|
```text
|
|
67
|
-
id displayName userPrincipalName userType
|
|
68
|
-
------------------------------------ -------------------- ------------------------------------ --------
|
|
69
|
-
da52218e-4822-4ac6-b41d-255e2059655e Adele Vance AdeleV@contoso.OnMicrosoft.com Member
|
|
91
|
+
id displayName userPrincipalName userType roles
|
|
92
|
+
------------------------------------ -------------------- ------------------------------------ -------- --------
|
|
93
|
+
da52218e-4822-4ac6-b41d-255e2059655e Adele Vance AdeleV@contoso.OnMicrosoft.com Owner,Member Owner,Member
|
|
70
94
|
```
|
|
71
95
|
|
|
72
96
|
</TabItem>
|
|
73
97
|
<TabItem value="CSV">
|
|
74
98
|
|
|
75
99
|
```csv
|
|
76
|
-
id,displayName,userPrincipalName,userType
|
|
77
|
-
da52218e-4822-4ac6-b41d-255e2059655e,Adele Vance,AdeleV@contoso.OnMicrosoft.com,Member
|
|
100
|
+
id,displayName,userPrincipalName,givenName,surname,userType
|
|
101
|
+
da52218e-4822-4ac6-b41d-255e2059655e,Adele Vance,AdeleV@contoso.OnMicrosoft.com,Adele,Vance,Member
|
|
78
102
|
```
|
|
79
103
|
|
|
80
104
|
</TabItem>
|
|
@@ -91,6 +115,8 @@ m365 aad m365group user list --groupId '00000000-0000-0000-0000-000000000000' --
|
|
|
91
115
|
---------|-------
|
|
92
116
|
id | da52218e-4822-4ac6-b41d-255e2059655e
|
|
93
117
|
displayName | Adele Vance
|
|
118
|
+
givenName | Adele
|
|
119
|
+
surname | Vance
|
|
94
120
|
userPrincipalName | AdeleV@contoso.OnMicrosoft.com
|
|
95
121
|
userType | Member
|
|
96
122
|
```
|
package/package.json
CHANGED