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

#1641- added ResourceBehaviorOptions to M365 Group creation #1774

Merged
merged 2 commits into from
Apr 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).

### Added
- Added `-Wait` and `-Verbose` optional paramarers to `New-PnPUPABulkImportJob` [#1752](https://github.com/pnp/powershell/pull/1752)
- Added `Add-PnpTeamsChannelUser` which allows members and owners to be added to private channels in Teams [#1735](https://github.com/pnp/powershell/pull/1735)
- Added `ResourceBehaviorOptions` option in `New-PnPMicrosoft365Group` cmdlet to set `ResourceBehaviorOptions` while provisioning a Microsoft 365 Group.
- Added `Add-PnPTeamsChannelUser` which allows members and owners to be added to private channels in Teams [#1735](https://github.com/pnp/powershell/pull/1735)
- Added `ExcludeVisualPromotedResults` parameter to `Get-PnPSearchConfiguration` which excludes promoted results [#1750](https://github.com/pnp/powershell/pull/1750)
- Added `MediaTranscription` parameter to `Set-PnPTenantSite` and `Set-PnPSite` cmdlets which when enabled allows videos to have transcripts generated on demand or generated automatically in certain scenarios
Expand Down
25 changes: 24 additions & 1 deletion documentation/New-PnPMicrosoft365Group.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Creates a new Microsoft 365 Group

```powershell
New-PnPMicrosoft365Group -DisplayName <String> -Description <String> -MailNickname <String>
[-Owners <String[]>] [-Members <String[]>] [-IsPrivate] [-LogoPath <String>] [-CreateTeam] [-HideFromAddressLists <Boolean>] [-HideFromOutlookClients <Boolean>] [-Force]
[-Owners <String[]>] [-Members <String[]>] [-IsPrivate] [-LogoPath <String>] [-CreateTeam] [-HideFromAddressLists <Boolean>] [-HideFromOutlookClients <Boolean>] [-ResourceBehaviorOptions <TeamResourceBehaviorOptions>] [-Force]
[<CommonParameters>]
```

Expand Down Expand Up @@ -57,6 +57,13 @@ New-PnPMicrosoft365Group -DisplayName $displayName -Description $description -Ma

Creates a private Microsoft 365 Group with all the required properties, and with a custom list of Owners and a custom list of Members

### EXAMPLE 5
```powershell
New-PnPMicrosoft365Group -DisplayName "myPnPDemo1" -Description $description -MailNickname $nickname -Owners $arrayOfOwners -Members $arrayOfMembers -IsPrivate -ResourceBehaviorOptions WelcomeEmailDisabled, HideGroupInOutlook
```

This will create a new Microsoft 365 Group called "myPnPDemo1" and sets the privacy to Private. Welcome Email will not be sent when the Group is created. The M365 Group will also not be visible in Outlook.

## PARAMETERS

### -CreateTeam
Expand Down Expand Up @@ -213,6 +220,22 @@ Accept pipeline input: False
Accept wildcard characters: False
```

### -ResourceBehaviorOptions

Allows providing ResourceBehaviorOptions which accepts multiple values that specify group behaviors for a Microsoft 365 Group.

```yaml
Type: TeamResourceBehaviorOptions
Parameter Sets: (All)
Accepted values: AllowOnlyMembersToPost, HideGroupInOutlook, SubscribeNewGroupMembers, WelcomeEmailDisabled

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
16 changes: 16 additions & 0 deletions src/Commands/Microsoft365Groups/NewMicrosoft365Group.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
using PnP.Framework.Graph;
using PnP.PowerShell.Commands.Attributes;
using PnP.PowerShell.Commands.Base;
using PnP.PowerShell.Commands.Enums;
using PnP.PowerShell.Commands.Model;
using PnP.PowerShell.Commands.Properties;
using PnP.PowerShell.Commands.Utilities;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Management.Automation;

Expand Down Expand Up @@ -48,6 +50,9 @@ public class NewPnPMicrosoft365Group : PnPGraphCmdlet
[Parameter(Mandatory = false)]
public SwitchParameter Force;

[Parameter(Mandatory = false)]
public TeamResourceBehaviorOptions?[] ResourceBehaviorOptions;

protected override void ExecuteCmdlet()
{
if (MailNickname.Contains(" "))
Expand Down Expand Up @@ -89,6 +94,17 @@ protected override void ExecuteCmdlet()
SecurityEnabled = false,
GroupTypes = new string[] { "Unified" }
};

if (ResourceBehaviorOptions != null && ResourceBehaviorOptions.Length > 0)
{
var teamResourceBehaviorOptionsValue = new List<string>();
for (int i = 0; i < ResourceBehaviorOptions.Length; i++)
{
teamResourceBehaviorOptionsValue.Add(ResourceBehaviorOptions[i].ToString());
}
newGroup.ResourceBehaviorOptions = teamResourceBehaviorOptionsValue.ToArray();
}

var group = Microsoft365GroupsUtility.CreateAsync(HttpClient, AccessToken, newGroup, CreateTeam, LogoPath, Owners, Members, HideFromAddressLists, HideFromOutlookClients).GetAwaiter().GetResult();

if (ParameterSpecified(nameof(HideFromAddressLists)) || ParameterSpecified(nameof(HideFromOutlookClients)))
Expand Down