protected override void ExecuteCmdlet() { bool forceCreation; if (!Force) { var existingGroup = UnifiedGroupsUtility.ListUnifiedGroups(AccessToken, mailNickname: MailNickname, endIndex: 1).Any(); forceCreation = !existingGroup || ShouldContinue(string.Format(Resources.ForceCreationOfExistingGroup0, MailNickname), Resources.Confirm); } else { forceCreation = true; } if (forceCreation) { var group = UnifiedGroupsUtility.CreateUnifiedGroup( DisplayName, Description, MailNickname, AccessToken, Owners, Members, GroupLogoPath, IsPrivate); WriteObject(group); } }
protected override void ExecuteCmdlet() { UnifiedGroupEntity group = null; List <UnifiedGroupEntity> groups = null; #pragma warning disable 0618 var includeSiteUrl = ParameterSpecified(nameof(ExcludeSiteUrl)) ? !ExcludeSiteUrl.ToBool() : IncludeSiteUrl.ToBool(); #pragma warning restore 0618 if (Identity != null) { group = Identity.GetGroup(AccessToken, includeSite: includeSiteUrl); } else { groups = UnifiedGroupsUtility.GetUnifiedGroups(AccessToken, includeSite: IncludeSiteUrl, includeClassification: IncludeClassification.IsPresent, includeHasTeam: IncludeHasTeam.IsPresent); } if (group != null) { WriteObject(group); } else if (groups != null) { WriteObject(groups, true); } }
public UnifiedGroupEntity GetGroup(string accessToken, bool includeClassification = false) { UnifiedGroupEntity group = null; if (Group != null) { group = UnifiedGroupsUtility.GetUnifiedGroup(Group.GroupId, accessToken, includeClassification: includeClassification); } else if (!String.IsNullOrEmpty(GroupId)) { group = UnifiedGroupsUtility.GetUnifiedGroup(GroupId, accessToken, includeClassification: includeClassification); } else if (!string.IsNullOrEmpty(DisplayName)) { var groups = UnifiedGroupsUtility.GetUnifiedGroups(accessToken, DisplayName, includeSite: true, includeClassification: includeClassification); if (groups == null || groups.Count == 0) { groups = UnifiedGroupsUtility.GetUnifiedGroups(accessToken, mailNickname: DisplayName, includeSite: true, includeClassification: includeClassification); } if (groups != null && groups.Any()) { group = groups.FirstOrDefault(); } } return(group); }
protected override void ExecuteCmdlet() { UnifiedGroupEntity group = null; if (Identity != null) { // We have to retrieve a specific group if (Identity.Group != null) { group = UnifiedGroupsUtility.GetUnifiedGroup(Identity.Group.GroupId, AccessToken, includeSite: false); } else if (!String.IsNullOrEmpty(Identity.GroupId)) { group = UnifiedGroupsUtility.GetUnifiedGroup(Identity.GroupId, AccessToken, includeSite: false); } } if (group != null) { // Get Owners of the group. List <UnifiedGroupUser> owners = UnifiedGroupsUtility.GetUnifiedGroupOwners(group, AccessToken); WriteObject(owners); } }
protected override void ExecuteCmdlet() { UnifiedGroupEntity group = null; if (Identity != null) { group = Identity.GetGroup(AccessToken); } Stream groupLogoStream = null; if (group != null) { if (GroupLogoPath != null) { if (!Path.IsPathRooted(GroupLogoPath)) { GroupLogoPath = Path.Combine(SessionState.Path.CurrentFileSystemLocation.Path, GroupLogoPath); } groupLogoStream = new FileStream(GroupLogoPath, FileMode.Open, FileAccess.Read); } UnifiedGroupsUtility.UpdateUnifiedGroup(group.GroupId, AccessToken, displayName: DisplayName, description: Description, owners: Owners, members: Members, groupLogo: groupLogoStream, isPrivate: IsPrivate); } else { WriteError(new ErrorRecord(new Exception("Group not found"), "GROUPNOTFOUND", ErrorCategory.ObjectNotFound, this)); } }
protected override void ExecuteCmdlet() { UnifiedGroupEntity group = null; if (Identity != null) { // We have to retrieve a specific group if (Identity.Group != null) { group = UnifiedGroupsUtility.GetUnifiedGroup(Identity.Group.GroupId, AccessToken); } else if (!String.IsNullOrEmpty(Identity.GroupId)) { group = UnifiedGroupsUtility.GetUnifiedGroup(Identity.GroupId, AccessToken); } } Stream groupLogoStream = null; if (group != null) { if (GroupLogoPath != null) { if (!Path.IsPathRooted(GroupLogoPath)) { GroupLogoPath = Path.Combine(SessionState.Path.CurrentFileSystemLocation.Path, GroupLogoPath); } groupLogoStream = new FileStream(GroupLogoPath, FileMode.Open, FileAccess.Read); } UnifiedGroupsUtility.UpdateUnifiedGroup(group.GroupId, AccessToken, displayName: DisplayName, description: Description, groupLogo: groupLogoStream); } }
public void RestoreDeletedUnifiedGroup() { UnifiedGroupsUtility.RestoreDeletedUnifiedGroup(_groupId, _accessToken); var results = UnifiedGroupsUtility.GetUnifiedGroup(_groupId, _accessToken); Assert.IsTrue(results != null && results.GroupId == _groupId); }
protected override void ExecuteCmdlet() { UnifiedGroupEntity group = null; if (Identity != null) { group = Identity.GetGroup(AccessToken); } Stream groupLogoStream = null; if (group != null) { if (GroupLogoPath != null) { if (!Path.IsPathRooted(GroupLogoPath)) { GroupLogoPath = Path.Combine(SessionState.Path.CurrentFileSystemLocation.Path, GroupLogoPath); } groupLogoStream = new FileStream(GroupLogoPath, FileMode.Open, FileAccess.Read); } bool?isPrivateGroup = null; if (IsPrivate.IsPresent) { isPrivateGroup = IsPrivate.ToBool(); } try { UnifiedGroupsUtility.UpdateUnifiedGroup( groupId: group.GroupId, accessToken: AccessToken, displayName: DisplayName, description: Description, owners: Owners, members: Members, groupLogo: groupLogoStream, isPrivate: isPrivateGroup, createTeam: CreateTeam); if (ParameterSpecified(nameof(HideFromAddressLists)) || ParameterSpecified(nameof(HideFromOutlookClients))) { // For this scenario a separate call needs to be made UnifiedGroupsUtility.SetUnifiedGroupVisibility(group.GroupId, AccessToken, HideFromAddressLists, HideFromOutlookClients); } } catch (Exception e) { while (e.InnerException != null) { e = e.InnerException; } WriteError(new ErrorRecord(e, "GROUPUPDATEFAILED", ErrorCategory.InvalidOperation, this)); } } else { WriteError(new ErrorRecord(new Exception("Group not found"), "GROUPNOTFOUND", ErrorCategory.ObjectNotFound, this)); } }
protected override void ExecuteCmdlet() { var group = Identity?.GetDeletedGroup(AccessToken); if (group != null) { UnifiedGroupsUtility.RestoreDeletedUnifiedGroup(group.GroupId, AccessToken); } }
public void ListDeletedUnifiedGroups() { if (string.IsNullOrEmpty(_accessToken)) { Assert.Inconclusive("Access token could not be retrieved, so skipping this test"); } var results = UnifiedGroupsUtility.ListDeletedUnifiedGroups(_accessToken); Assert.IsTrue(results.Count > 0); }
public void GetDeletedUnifiedGroup() { if (string.IsNullOrEmpty(_accessToken)) { Assert.Inconclusive("Access token could not be retrieved, so skipping this test"); } var results = UnifiedGroupsUtility.GetDeletedUnifiedGroup(_groupId, _accessToken); Assert.IsTrue(results != null && results.GroupId == _groupId); }
protected override void ExecuteCmdlet() { if (Identity != null) { UnifiedGroupEntity group = Identity.GetGroup(AccessToken); if (group != null) { UnifiedGroupsUtility.DeleteUnifiedGroup(group.GroupId, AccessToken); } } }
public void Initialize() { _accessToken = TestCommon.AcquireTokenAsync("https://graph.microsoft.com"); TestCommon.FixAssemblyResolving("Newtonsoft.Json"); var random = new Random(); _groupId = UnifiedGroupsUtility.CreateUnifiedGroup("PnPDeletedUnifiedGroup test", "PnPDeletedUnifiedGroup test", $"pnp-unit-test-{random.Next(1, 1000)}", _accessToken, groupLogo: null).GroupId; UnifiedGroupsUtility.DeleteUnifiedGroup(_groupId, _accessToken); }
/// <summary> /// Checks if this site collection has a Teams team linked /// </summary> /// <param name="site">Site collection</param> /// <param name="accessToken">Graph access token (groups.read.all) </param> /// <returns>True if there's a team</returns> public static bool HasTeamsTeam(this Site site, string accessToken) { bool result = false; site.EnsureProperties(s => s.RootWeb, s => s.GroupId); // A site without a group cannot have been teamified if (site.GroupId == Guid.Empty) { return(false); } // fall back to Graph untill we've a SharePoint approach that works result = UnifiedGroupsUtility.HasTeamsTeam(site.GroupId.ToString(), accessToken); // Problem is that this folder property is not always set /* * site.EnsureProperties(s => s.RootWeb, s => s.GroupId); * List defaultDocumentLibrary = site.RootWeb.DefaultDocumentLibrary(); * site.RootWeb.Context.Load(defaultDocumentLibrary, f=>f.RootFolder); * site.RootWeb.Context.ExecuteQueryRetry(); * * if (defaultDocumentLibrary.RootFolder.FolderExists("General")) * { * // Load folder properties * var generalFolder = defaultDocumentLibrary.RootFolder.EnsureFolder("General", p => p.Properties); * site.RootWeb.Context.Load(generalFolder); * site.RootWeb.Context.ExecuteQueryRetry(); * * // Do we have the Teams channel entry ? * string Vti_TeamChannelUrl = "vti_teamchannelurl"; * * if (generalFolder.Properties.FieldValues.ContainsKey(Vti_TeamChannelUrl)) * { * var teamChannelUrl = generalFolder.Properties.FieldValues[Vti_TeamChannelUrl]?.ToString(); * if (!string.IsNullOrEmpty(teamChannelUrl)) * { * // Sample teams url: https://teams.microsoft.com/l/channel/19%3A0000866a32964362b5db23f21f81704c%40thread.skype/General?groupId=c1430c5f-c423-44b8-b083-bd81ca3f09d0&tenantId=ad20b775-5d3b-40f5-b144-c5c2c772b73e * // Just verify the url has a reference to the site's group id * if (teamChannelUrl.ToLower().Contains(site.GroupId.ToString().ToLower())) * { * return true; * } * } * } * } */ return(result); }
protected override void ExecuteCmdlet() { UnifiedGroupEntity group = null; if (Identity != null) { group = Identity.GetGroup(AccessToken); } if (group != null) { UnifiedGroupsUtility.AddUnifiedGroupMembers(group.GroupId, Users, AccessToken, RemoveExisting.ToBool()); } }
protected override void ExecuteCmdlet() { UnifiedGroupEntity group = null; if (Identity != null) { group = Identity.GetGroup(AccessToken); } if (group != null) { UnifiedGroupsUtility.ClearUnifiedGroupMembers(group.GroupId, AccessToken); } }
protected override void ExecuteCmdlet() { UnifiedGroupEntity group = null; if (Identity != null) { group = Identity.GetGroup(AccessToken); } if (group != null) { UnifiedGroupsUtility.RemoveUnifiedGroupOwners(group.GroupId, Users, AccessToken); } }
public UnifiedGroupEntity GetDeletedGroup(string accessToken) { UnifiedGroupEntity group = null; if (Group != null) { group = UnifiedGroupsUtility.GetDeletedUnifiedGroup(Group.GroupId, accessToken); } else if (!string.IsNullOrEmpty(GroupId)) { group = UnifiedGroupsUtility.GetDeletedUnifiedGroup(GroupId, accessToken); } return(group); }
public void PermanentlyDeleteUnifiedGroup() { UnifiedGroupsUtility.PermanentlyDeleteUnifiedGroup(_groupId, _accessToken); // The group should no longer be found in deleted groups try { var results = UnifiedGroupsUtility.GetDeletedUnifiedGroup(_groupId, _accessToken); Assert.IsFalse(results != null); } catch (Exception) { Assert.IsTrue(true); } }
protected override void ExecuteCmdlet() { UnifiedGroupEntity group = null; if (Identity != null) { group = Identity.GetGroup(AccessToken, false); } if (group != null) { // Get Owners of the group List <UnifiedGroupUser> owners = UnifiedGroupsUtility.GetUnifiedGroupOwners(group, AccessToken); WriteObject(owners); } }
protected override void ExecuteCmdlet() { if (PnPConnection.CurrentConnection.ClientId == PnPConnection.PnPManagementShellClientId) { PnPConnection.CurrentConnection.Scopes = new[] { "Group.ReadWrite.All" }; } UnifiedGroupEntity group = null; if (Identity != null) { group = Identity.GetGroup(AccessToken, false); } if (group != null) { UnifiedGroupsUtility.AddUnifiedGroupMembers(group.GroupId, Users, AccessToken, RemoveExisting.ToBool()); } }
public void CleanUp() { try { UnifiedGroupsUtility.DeleteUnifiedGroup(_groupId, _accessToken); } catch (Exception) { // Group has already been deleted } try { UnifiedGroupsUtility.PermanentlyDeleteUnifiedGroup(_groupId, _accessToken); } catch (Exception) { // Group has already been permanently deleted } }
public void PermanentlyDeleteUnifiedGroup() { if (string.IsNullOrEmpty(_accessToken)) { Assert.Inconclusive("Access token could not be retrieved, so skipping this test"); } UnifiedGroupsUtility.PermanentlyDeleteUnifiedGroup(_groupId, _accessToken); // The group should no longer be found in deleted groups try { var results = UnifiedGroupsUtility.GetDeletedUnifiedGroup(_groupId, _accessToken); Assert.IsFalse(results != null); } catch (Exception) { Assert.IsTrue(true); } }
protected override void ExecuteCmdlet() { UnifiedGroupEntity group = null; List <UnifiedGroupEntity> groups = null; if (Identity != null) { // We have to retrieve a specific group if (Identity.Group != null) { group = UnifiedGroupsUtility.GetUnifiedGroup(Identity.Group.GroupId, AccessToken, includeSite: !ExcludeSiteUrl.IsPresent); } else if (!String.IsNullOrEmpty(Identity.DisplayName)) { groups = UnifiedGroupsUtility.ListUnifiedGroups(AccessToken, Identity.DisplayName, includeSite: !ExcludeSiteUrl.IsPresent); if (groups == null || groups.Count == 0) { groups = UnifiedGroupsUtility.ListUnifiedGroups(AccessToken, mailNickname: Identity.DisplayName, includeSite: !ExcludeSiteUrl.IsPresent); } } else if (!String.IsNullOrEmpty(Identity.GroupId)) { group = UnifiedGroupsUtility.GetUnifiedGroup(Identity.GroupId, AccessToken, includeSite: !ExcludeSiteUrl.IsPresent); } } else { // Retrieve all the groups groups = UnifiedGroupsUtility.ListUnifiedGroups(AccessToken, includeSite: !ExcludeSiteUrl.IsPresent); } if (group != null) { WriteObject(group); } else if (groups != null) { WriteObject(groups, true); } }
protected override void ExecuteCmdlet() { if (Identity != null) { UnifiedGroupEntity group = null; // We have to retrieve a specific group if (Identity.Group != null) { group = UnifiedGroupsUtility.GetUnifiedGroup(Identity.Group.GroupId, AccessToken); } else if (!String.IsNullOrEmpty(Identity.GroupId)) { group = UnifiedGroupsUtility.GetUnifiedGroup(Identity.GroupId, AccessToken); } if (group != null) { UnifiedGroupsUtility.DeleteUnifiedGroup(group.GroupId, AccessToken); } } }
protected override void ExecuteCmdlet() { if (MailNickname.Contains(" ")) { throw new ArgumentException("MailNickname cannot contain spaces."); } bool forceCreation; if (!Force) { var candidates = UnifiedGroupsUtility.GetUnifiedGroups(AccessToken, mailNickname: MailNickname, endIndex: 1); // ListUnifiedGroups retrieves groups with starts-with, so need another check var existingGroup = candidates.Any(g => g.MailNickname.Equals(MailNickname, StringComparison.CurrentCultureIgnoreCase)); forceCreation = !existingGroup || ShouldContinue(string.Format(Resources.ForceCreationOfExistingGroup0, MailNickname), Resources.Confirm); } else { forceCreation = true; } if (forceCreation) { var group = UnifiedGroupsUtility.CreateUnifiedGroup( displayName: DisplayName, description: Description, mailNickname: MailNickname, accessToken: AccessToken, owners: Owners, members: Members, groupLogoPath: GroupLogoPath, isPrivate: IsPrivate, createTeam: CreateTeam); WriteObject(group); } }
protected override void ExecuteCmdlet() { UnifiedGroupEntity group = null; List <UnifiedGroupEntity> groups = null; if (Identity != null) { group = Identity.GetDeletedGroup(AccessToken); } else { groups = UnifiedGroupsUtility.ListDeletedUnifiedGroups(AccessToken); } if (group != null) { WriteObject(group); } else if (groups != null) { WriteObject(groups, true); } }
protected override void ExecuteCmdlet() { UnifiedGroupEntity group = null; List <UnifiedGroupEntity> groups = null; if (Identity != null) { // We have to retrieve a specific group if (Identity.Group != null) { group = UnifiedGroupsUtility.GetUnifiedGroup(Identity.Group.GroupId, AccessToken); } else if (!String.IsNullOrEmpty(Identity.DisplayName)) { groups = UnifiedGroupsUtility.ListUnifiedGroups(AccessToken, Identity.DisplayName); } else if (!String.IsNullOrEmpty(Identity.GroupId)) { group = UnifiedGroupsUtility.GetUnifiedGroup(Identity.GroupId, AccessToken); } } else { // Retrieve all the groups groups = UnifiedGroupsUtility.ListUnifiedGroups(AccessToken); } if (group != null) { WriteObject(group); } else if (groups != null) { WriteObject(groups, true); } }
protected override void ExecuteCmdlet() { UnifiedGroupEntity group = null; List <UnifiedGroupEntity> groups = null; if (Identity != null) { group = Identity.GetGroup(AccessToken); } else { // Retrieve all the groups groups = UnifiedGroupsUtility.ListUnifiedGroups(AccessToken, includeSite: !ExcludeSiteUrl.IsPresent, includeClassification: IncludeClassification.IsPresent, includeHasTeam: IncludeHasTeam.IsPresent); } if (group != null) { WriteObject(group); } else if (groups != null) { WriteObject(groups, true); } }
protected override void ExecuteCmdlet() { var group = Identity.GetGroup(AccessToken); UnifiedGroupsUtility.RenewUnifiedGroup(group.GroupId, AccessToken); }