protected override void ExecuteCmdlet() { if (MailNickname.Contains(" ")) { throw new ArgumentException("MailNickname cannot contain spaces."); } bool forceCreation; if (!Force) { var candidate = Microsoft365GroupsUtility.GetGroupAsync(HttpClient, MailNickname, AccessToken, false, false).GetAwaiter().GetResult(); forceCreation = candidate == null || ShouldContinue($"The Microsoft 365 Group '{MailNickname} already exists. Do you want to create a new one?", Resources.Confirm); } else { forceCreation = true; } if (forceCreation) { if (ParameterSpecified(nameof(LogoPath))) { if (System.IO.Path.IsPathRooted(LogoPath)) { LogoPath = System.IO.Path.Combine(SessionState.Path.CurrentFileSystemLocation.Path, LogoPath); } if (!System.IO.File.Exists(LogoPath)) { throw new PSArgumentException("File specified for logo does not exist."); } } var newGroup = new Microsoft365Group() { DisplayName = DisplayName, Description = Description, MailNickname = MailNickname, Visibility = IsPrivate ? "Private" : "Public", MailEnabled = true, SecurityEnabled = false, GroupTypes = new string[] { "Unified" } }; var group = Microsoft365GroupsUtility.CreateAsync(HttpClient, AccessToken, newGroup, CreateTeam, LogoPath, Owners, Members, HideFromAddressLists, HideFromOutlookClients).GetAwaiter().GetResult(); if (ParameterSpecified(nameof(HideFromAddressLists)) || ParameterSpecified(nameof(HideFromOutlookClients))) { Microsoft365GroupsUtility.SetVisibilityAsync(HttpClient, AccessToken, group.Id.Value, HideFromAddressLists, HideFromOutlookClients).GetAwaiter().GetResult(); } var updatedGroup = Microsoft365GroupsUtility.GetGroupAsync(HttpClient, group.Id.Value, AccessToken, true, false).GetAwaiter().GetResult(); WriteObject(updatedGroup); } }
public Microsoft365Group GetGroup(HttpClient httpClient, string accessToken, bool includeSite, bool includeOwners) { Microsoft365Group group = null; if (Group != null) { group = Microsoft365GroupsUtility.GetGroupAsync(httpClient, _group.Id.Value, accessToken, includeSite, includeOwners).GetAwaiter().GetResult(); } else if (_groupId != Guid.Empty) { group = Microsoft365GroupsUtility.GetGroupAsync(httpClient, _groupId, accessToken, includeSite, includeOwners).GetAwaiter().GetResult(); } else if (!string.IsNullOrEmpty(DisplayName)) { group = Microsoft365GroupsUtility.GetGroupAsync(httpClient, DisplayName, accessToken, includeSite, includeOwners).GetAwaiter().GetResult(); } return group; }
public Guid GetGroupId(HttpClient httpClient, string accessToken) { if (Group != null) { return _group.Id.Value; } else if (_groupId != Guid.Empty) { return _groupId; } else if (!string.IsNullOrEmpty(DisplayName)) { var group = Microsoft365GroupsUtility.GetGroupAsync(httpClient, DisplayName, accessToken, false, false).GetAwaiter().GetResult(); if (group != null) { return group.Id.Value; } } throw new PSInvalidOperationException("Group not found"); //return Guid.Empty; }