Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#1021 - New-PnPTeamsTeam , ability to add multiple owners and members #1241

Merged
merged 35 commits into from
Jan 26, 2022
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
21e9727
#1021 , #1022 - added ability to add multiple owners and members
gautamdsheth Oct 12, 2021
330065e
Empty owner logic change
gautamdsheth Oct 12, 2021
f2f9615
Added changelog entry
gautamdsheth Oct 12, 2021
d43f03b
Merge branch 'dev' into feature/1021
KoenZomers Oct 13, 2021
14855b4
Merge branch 'dev' into feature/1021
gautamdsheth Oct 17, 2021
4330694
Implement batch add of members and owners
gautamdsheth Oct 17, 2021
63fa976
Merge branch 'dev' into feature/1021
gautamdsheth Nov 14, 2021
3e62dd3
Fixed merge changes
gautamdsheth Nov 14, 2021
0ea0af1
Merge branch 'dev' into feature/1021
gautamdsheth Dec 14, 2021
b666694
Fixes as per review comments
gautamdsheth Dec 14, 2021
b556498
Updated docs form Set-PnPTenant
gautamdsheth Dec 14, 2021
fc0d9f2
Undo docs update
gautamdsheth Dec 14, 2021
d9f5602
Merge branch 'dev' into feature/1021
KoenZomers Dec 20, 2021
7574489
Rebuilt logic
KoenZomers Dec 21, 2021
3f5df81
Fixed chunk add logic, Graph only allows 20 users at a time
gautamdsheth Dec 21, 2021
3e99cea
Updated changelog
gautamdsheth Dec 21, 2021
0ffe0d3
Author credit
gautamdsheth Dec 21, 2021
c7879ac
Fix handling owner if not specified
gautamdsheth Dec 22, 2021
2d48172
whitespace change
gautamdsheth Dec 22, 2021
1405bfb
Updating code to better handle not providing owners
KoenZomers Dec 22, 2021
e50ded9
Adding todo to check on adding owners as members
KoenZomers Dec 22, 2021
984c829
Merge branch 'feature/1021' of https://github.com/gautamdsheth/powers…
gautamdsheth Dec 22, 2021
044b1a3
Added some code comments
KoenZomers Dec 22, 2021
a33a680
Changed adding additional members and owners to add them by UPN in 1 …
KoenZomers Dec 22, 2021
7e1c291
Removing commented out line to add the first owner as an owner and a …
KoenZomers Dec 22, 2021
9983bc4
Merge branch 'dev' into feature/1021
gautamdsheth Dec 26, 2021
55e532a
Split Owners and Members in array of 20 and then add them to the team
gautamdsheth Dec 26, 2021
1772faa
Merge branch 'dev' into feature/1021
gautamdsheth Jan 15, 2022
093583c
Fix changelog entry issue
gautamdsheth Jan 15, 2022
cf4f0f2
Upping batches to 200 based on developer feedback
KoenZomers Jan 19, 2022
63bfd6f
Merge branch 'dev' into feature/1021
gautamdsheth Jan 22, 2022
5f780cf
Merge branch 'feature/1021' of https://github.com/gautamdsheth/powers…
gautamdsheth Jan 22, 2022
806f62b
Updated as per discussed
gautamdsheth Jan 22, 2022
950cda2
Removing redundant ToList
KoenZomers Jan 26, 2022
9b84f5b
Merge branch 'dev' into feature/1021
KoenZomers Jan 26, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
- Removed `Add-PnPClientSidePage` as that was marked deprecated. Use `Add-PnPPage` instead.
- Added optional `-ScheduledPublishDate` parameter to `Add-PnPPage` and `Set-PnPPage` to allow for scheduling a page to be published.
- Added `-RemoveScheduledPublish` to `Set-PnPPage` to allow for a page publish schedule to be removed.
- Added support to add multiple owners and members in `New-PnPTeamsTeam` cmdlet.
- Improved `Get-PnPFile` cmdlet to handle large file downloads.
- Added support for off peak SharePoint Syntex content classification and extraction for lists and folders via new `-OffPeak` and `-Folder` parameters for `Request-PnPSyntexClassifyAndExtract`.
- Fix `Set-PnPListItem` not working when using `Label` and `Values` parameters together.
Expand Down
31 changes: 30 additions & 1 deletion documentation/New-PnPTeamsTeam.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ New-PnPTeamsTeam -GroupId <String> [-Owner <String>] [-AllowAddRemoveApps <Boole
[-AllowOwnerDeleteMessages <Boolean>] [-AllowStickersAndMemes <Boolean>] [-AllowTeamMentions <Boolean>]
[-AllowUserDeleteMessages <Boolean>] [-AllowUserEditMessages <Boolean>]
[-GiphyContentRating <TeamGiphyContentRating>] [-ShowInTeamsSearchAndSuggestions <Boolean>]
[-Classification <String>] [<CommonParameters>]
[-Classification <String>] [-Owners <String[]>] [-Members <String[]>] [<CommonParameters>]
```

### For a new group
Expand All @@ -43,6 +43,7 @@ New-PnPTeamsTeam -DisplayName <String> [-MailNickName <String>] [-Description <S
[-AllowUserDeleteMessages <Boolean>] [-AllowUserEditMessages <Boolean>]
[-GiphyContentRating <TeamGiphyContentRating>] [-Visibility <TeamVisibility>]
[-ShowInTeamsSearchAndSuggestions <Boolean>] [-Classification <String>]
[-Owners <String[]>] [-Members <String[]>]
[<CommonParameters>]
```

Expand Down Expand Up @@ -403,6 +404,34 @@ Accept pipeline input: False
Accept wildcard characters: False
```

### -Owners
The UPN(s) of the user(s) to be added to the Microsoft 365 group as a owners.

```yaml
Type: String[]
Parameter Sets: (All)

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```

### -Members
The UPN(s) of the user(s) to be added to the Microsoft 365 group as a members.

```yaml
Type: String[]
Parameter Sets: (All)

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```

## RELATED LINKS

[Microsoft 365 Patterns and Practices](https://aka.ms/m365pnp)
Expand Down
10 changes: 8 additions & 2 deletions src/Commands/Teams/NewTeamsTeam.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,13 @@ public class NewTeamsTeam : PnPGraphCmdlet
public TeamsTemplateType Template = TeamsTemplateType.None;

[Parameter(Mandatory = false, ParameterSetName = ParameterAttribute.AllParameterSets)]
public bool? AllowCreatePrivateChannels;
public bool? AllowCreatePrivateChannels;

[Parameter(Mandatory = false, ParameterSetName = ParameterAttribute.AllParameterSets)]
public string[] Owners;

[Parameter(Mandatory = false, ParameterSetName = ParameterAttribute.AllParameterSets)]
public string[] Members;

protected override void ExecuteCmdlet()
{
Expand Down Expand Up @@ -125,7 +131,7 @@ protected override void ExecuteCmdlet()
Visibility = (GroupVisibility)Enum.Parse(typeof(GroupVisibility), Visibility.ToString()),
AllowCreatePrivateChannels = AllowCreatePrivateChannels,
};
WriteObject(TeamsUtility.NewTeamAsync(AccessToken, HttpClient, GroupId, DisplayName, Description, Classification, MailNickName, Owner, (GroupVisibility)Enum.Parse(typeof(GroupVisibility), Visibility.ToString()), teamCI, Template).GetAwaiter().GetResult());
WriteObject(TeamsUtility.NewTeamAsync(AccessToken, HttpClient, GroupId, DisplayName, Description, Classification, MailNickName, Owner, (GroupVisibility)Enum.Parse(typeof(GroupVisibility), Visibility.ToString()), teamCI, Owners, Members, Template).GetAwaiter().GetResult());
}
}
}
43 changes: 32 additions & 11 deletions src/Commands/Utilities/TeamsUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public static async Task<Team> GetTeamAsync(string accessToken, HttpClient httpC
{
team.DisplayName = group.DisplayName;
team.MailNickname = group.MailNickname;
team.Visibility = group.Visibility;
team.Visibility = group.Visibility;
return team;
}
else
Expand Down Expand Up @@ -104,14 +104,14 @@ private static async Task<Team> ParseTeamJsonAsync(string accessToken, HttpClien
}
}

public static async Task<Team> NewTeamAsync(string accessToken, HttpClient httpClient, string groupId, string displayName, string description, string classification, string mailNickname, string owner, GroupVisibility visibility, TeamCreationInformation teamCI, TeamsTemplateType templateType = TeamsTemplateType.None)
public static async Task<Team> NewTeamAsync(string accessToken, HttpClient httpClient, string groupId, string displayName, string description, string classification, string mailNickname, string owner, GroupVisibility visibility, TeamCreationInformation teamCI, string[] owners, string[] members, TeamsTemplateType templateType = TeamsTemplateType.None)
{
Group group = null;
Team returnTeam = null;
// Create group
if (string.IsNullOrEmpty(groupId))
{
group = await CreateGroupAsync(accessToken, httpClient, displayName, description, classification, mailNickname, owner, visibility, templateType);
group = await CreateGroupAsync(accessToken, httpClient, displayName, description, classification, mailNickname, owner, visibility, owners, templateType);
bool wait = true;
int iterations = 0;
while (wait)
Expand Down Expand Up @@ -151,6 +151,16 @@ public static async Task<Team> NewTeamAsync(string accessToken, HttpClient httpC
}
if (group != null)
{
if (owners != null && owners.Length > 0)
{
Framework.Graph.GroupsUtility.AddGroupOwners(group.Id, owners, accessToken, false);
}

if (members != null && members.Length > 0)
{
Framework.Graph.GroupsUtility.AddGroupMembers(group.Id, members, accessToken, false);
}

Team team = teamCI.ToTeam(group.Visibility);
var retry = true;
var iteration = 0;
Expand All @@ -161,7 +171,7 @@ public static async Task<Team> NewTeamAsync(string accessToken, HttpClient httpC
var teamSettings = await GraphHelper.PutAsync(httpClient, $"v1.0/groups/{group.Id}/team", team, accessToken);
if (teamSettings != null)
{
returnTeam = await TeamsUtility.GetTeamAsync(accessToken, httpClient, group.Id);
returnTeam = await GetTeamAsync(accessToken, httpClient, group.Id);
}
retry = false;
}
Expand All @@ -181,15 +191,23 @@ public static async Task<Team> NewTeamAsync(string accessToken, HttpClient httpC
return returnTeam;
}

private static async Task<Group> CreateGroupAsync(string accessToken, HttpClient httpClient, string displayName, string description, string classification, string mailNickname, string owner, GroupVisibility visibility, TeamsTemplateType templateType = TeamsTemplateType.None)
private static async Task<Group> CreateGroupAsync(string accessToken, HttpClient httpClient, string displayName, string description, string classification, string mailNickname, string owner, GroupVisibility visibility, string[] owners, TeamsTemplateType templateType = TeamsTemplateType.None)
{
Group group = new Group();
// get the owner if no owner was specified
var ownerId = string.Empty;
if (string.IsNullOrEmpty(owner))
{
var user = await GraphHelper.GetAsync<User>(httpClient, "v1.0/me?$select=Id", accessToken);
ownerId = user.Id;
if (owners != null && owners.Length > 0)
{
var user = await GraphHelper.GetAsync<User>(httpClient, $"v1.0/users/{owners[0]}?$select=Id", accessToken);
gautamdsheth marked this conversation as resolved.
Show resolved Hide resolved
ownerId = user.Id;
}
else
{
var user = await GraphHelper.GetAsync<User>(httpClient, "v1.0/me?$select=Id", accessToken);
gautamdsheth marked this conversation as resolved.
Show resolved Hide resolved
ownerId = user.Id;
}
}
else
{
Expand Down Expand Up @@ -246,12 +264,15 @@ private static async Task<Group> CreateGroupAsync(string accessToken, HttpClient
try
{
return await GraphHelper.PostAsync<Group>(httpClient, "v1.0/groups", group, accessToken);
} catch (GraphException ex)
}
catch (GraphException ex)
{
if(ex.Error.Message.Contains("extension_fe2174665583431c953114ff7268b7b3_Education_ObjectType"))
if (ex.Error.Message.Contains("extension_fe2174665583431c953114ff7268b7b3_Education_ObjectType"))
{
throw new PSInvalidOperationException("Invalid EDU license type");
} else {
}
else
{
throw;
}
}
Expand Down Expand Up @@ -396,7 +417,7 @@ public static async Task<IEnumerable<User>> GetUsersAsync(HttpClient httpClient,
{
users.AddRange(collection.Select(m => new User() { DisplayName = m.DisplayName, Id = m.UserId, UserPrincipalName = m.email, UserType = m.Roles.Count > 0 ? m.Roles[0].ToLower() : "" }));
}

if (selectedRole != null)
{
return users.Where(u => u.UserType == selectedRole);
Expand Down