diff --git a/src/Commands/Microsoft365Groups/NewMicrosoft365Group.cs b/src/Commands/Microsoft365Groups/NewMicrosoft365Group.cs index b120f4984..e21a49149 100644 --- a/src/Commands/Microsoft365Groups/NewMicrosoft365Group.cs +++ b/src/Commands/Microsoft365Groups/NewMicrosoft365Group.cs @@ -1,12 +1,17 @@ using Microsoft.SharePoint.Client; + using PnP.PowerShell.Commands.Attributes; using PnP.PowerShell.Commands.Base; using PnP.PowerShell.Commands.Enums; using PnP.PowerShell.Commands.Model; using PnP.PowerShell.Commands.Utilities; + using System; +using System.Collections; using System.Collections.Generic; +using System.Linq; using System.Management.Automation; +using System.Management.Automation.Language; namespace PnP.PowerShell.Commands.Microsoft365Groups { @@ -23,12 +28,22 @@ public class NewPnPMicrosoft365Group : PnPGraphCmdlet [Parameter(Mandatory = true)] public String MailNickname; + [Parameter(Mandatory = false)] + public bool MailEnabled = true; + [Parameter(Mandatory = false)] public String[] Owners; [Parameter(Mandatory = false)] public String[] Members; + [Parameter(Mandatory = false)] + [ArgumentCompleter(typeof(EnumAsStringArgumentCompleter))] + public string PreferredDataLocation; + + [Parameter(Mandatory = false)] + public string PreferredLanguage; + [Parameter(Mandatory = false)] public SwitchParameter IsPrivate; @@ -49,11 +64,15 @@ public class NewPnPMicrosoft365Group : PnPGraphCmdlet public SwitchParameter Force; [Parameter(Mandatory = false)] + [ArgumentCompleter(typeof(EnumAsStringArgumentCompleter))] public TeamResourceBehaviorOptions?[] ResourceBehaviorOptions; [Parameter(Mandatory = false)] public Guid[] SensitivityLabels; + [Parameter(Mandatory = false)] + public SwitchParameter SecurityEnabled; + protected override void ExecuteCmdlet() { if (MailNickname.Contains(" ")) @@ -91,9 +110,11 @@ protected override void ExecuteCmdlet() Description = Description, MailNickname = MailNickname, Visibility = IsPrivate ? "Private" : "Public", - MailEnabled = true, - SecurityEnabled = false, - GroupTypes = new string[] { "Unified" } + MailEnabled = MailEnabled, + SecurityEnabled = SecurityEnabled, + GroupTypes = new string[] { "Unified" }, + PreferredDataLocation = PreferredDataLocation, + PreferredLanguage = PreferredLanguage, }; if (ResourceBehaviorOptions != null && ResourceBehaviorOptions.Length > 0) @@ -123,7 +144,7 @@ protected override void ExecuteCmdlet() else { WriteWarning("Adding sensitivity labels in App-only context is not supported by Graph API, so it will be skipped in Group creation"); - } + } } var group = Microsoft365GroupsUtility.CreateAsync(Connection, AccessToken, newGroup, CreateTeam, LogoPath, Owners, Members, HideFromAddressLists, HideFromOutlookClients, Labels).GetAwaiter().GetResult(); diff --git a/src/Commands/Utilities/EnumAsStringArgumentCompleter.cs b/src/Commands/Utilities/EnumAsStringArgumentCompleter.cs new file mode 100644 index 000000000..3c456edde --- /dev/null +++ b/src/Commands/Utilities/EnumAsStringArgumentCompleter.cs @@ -0,0 +1,26 @@ +using PnP.PowerShell.Commands.Utilities; + +using System; +using System.Collections; +using System.Collections.Generic; +using System.Linq; +using System.Management.Automation; +using System.Management.Automation.Language; + +namespace PnP.PowerShell.Commands.Utilities +{ + /// + /// Allow argument completion of enums without prohibiting undefined values. + /// ie. to allow for future extension + /// + /// + internal sealed class EnumAsStringArgumentCompleter : IArgumentCompleter where TEnum : struct, Enum + { + public IEnumerable CompleteArgument(string commandName, string parameterName, string wordToComplete, CommandAst commandAst, IDictionary fakeBoundParameters) + { + return Enum.GetNames(typeof(TEnum)) + .Where(x => x.StartsWith(wordToComplete, StringComparison.OrdinalIgnoreCase)) + .Select(x => new CompletionResult(x, x, CompletionResultType.ParameterValue, x)); + } + } +} \ No newline at end of file