Beispiel #1
0
 protected override void ExecuteCmdlet()
 {
     if (Identity != null)
     {
         WriteObject(Identity.GetDeletedGroup(HttpClient, AccessToken));
     }
     else
     {
         var groups = Microsoft365GroupsUtility.GetDeletedGroupsAsync(HttpClient, AccessToken).GetAwaiter().GetResult();
         WriteObject(groups.OrderBy(g => g.DisplayName), true);
     }
 }
        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);
            }
        }
        protected override void ExecuteCmdlet()
        {
            var groupId = Identity.GetGroupId(HttpClient, AccessToken);

            Microsoft365GroupsUtility.ClearOwnersAsync(HttpClient, groupId, AccessToken).GetAwaiter().GetResult();
            var owners = Microsoft365GroupsUtility.GetOwnersAsync(HttpClient, groupId, AccessToken).GetAwaiter().GetResult();

            if (owners != null && owners.Any())
            {
                WriteWarning($"Clearing all owners is not possible as there will always have to be at least one owner. To changed the owners with new owners use Set-PnPMicrosoft365GroupOwner -Identity {groupId} -Owners \"[email protected]\"");
                WriteWarning($"Current owner is: {owners.First().UserPrincipalName}");
            }
        }
Beispiel #4
0
 public Microsoft365Group GetDeletedGroup(HttpClient httpClient, string accessToken)
 {
     if (_group != null)
     {
         return Microsoft365GroupsUtility.GetDeletedGroupAsync(httpClient, _group.Id.Value, accessToken).GetAwaiter().GetResult();
     }
     else if (_groupId != Guid.Empty)
     {
         return Microsoft365GroupsUtility.GetDeletedGroupAsync(httpClient, _groupId, accessToken).GetAwaiter().GetResult();
     }
     else if (!string.IsNullOrEmpty(_displayName))
     {
         return Microsoft365GroupsUtility.GetDeletedGroupAsync(httpClient, _displayName, accessToken).GetAwaiter().GetResult();
     }
     return null;
 }
Beispiel #5
0
 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;
 }
        protected override void ExecuteCmdlet()
        {
#pragma warning disable 0618
            var includeSiteUrl = ParameterSpecified(nameof(ExcludeSiteUrl)) ? !ExcludeSiteUrl.ToBool() : IncludeSiteUrl.ToBool();
#pragma warning restore 0618

            if (Identity != null)
            {
                var group = Identity.GetGroup(HttpClient, AccessToken, includeSiteUrl, IncludeOwners);
                WriteObject(group);
            }
            else
            {
                var groups = Microsoft365GroupsUtility.GetGroupsAsync(HttpClient, AccessToken, includeSiteUrl, IncludeOwners).GetAwaiter().GetResult();

                WriteObject(groups.OrderBy(p => p.DisplayName), true);
            }
        }
Beispiel #7
0
 public Guid GetDeletedGroupId(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.GetDeletedGroupAsync(httpClient, _displayName, accessToken).GetAwaiter().GetResult();
         if (group != null)
         {
             return group.Id.Value;
         }
     }
     throw new PSInvalidOperationException("Deleted group not found");
 }
Beispiel #8
0
 protected override void ExecuteCmdlet()
 {
     try
     {
         var results      = SiteCollection.TeamifySiteAsync(ClientContext);
         var returnedBool = results.GetAwaiter().GetResult();
         WriteObject(returnedBool);
     }
     catch (Exception)
     {
         try
         {
             var groupId = ClientContext.Site.EnsureProperty(s => s.GroupId);
             Microsoft365GroupsUtility.CreateTeamAsync(HttpClient, AccessToken, groupId).GetAwaiter().GetResult();
         }
         catch
         {
             throw;
         }
     }
 }
 protected override void ExecuteCmdlet()
 {
     Microsoft365GroupsUtility.RemoveOwnersAsync(HttpClient, Identity.GetGroupId(HttpClient, AccessToken), Users, AccessToken).GetAwaiter().GetResult();
 }
Beispiel #10
0
 protected override void ExecuteCmdlet()
 {
     Microsoft365GroupsUtility.PermanentlyDeleteDeletedGroupAsync(HttpClient, Identity.GetDeletedGroupId(HttpClient, AccessToken), AccessToken).GetAwaiter().GetResult();
 }
Beispiel #11
0
        protected override void ExecuteCmdlet()
        {
            var owners = Microsoft365GroupsUtility.GetOwnersAsync(HttpClient, Identity.GetGroupId(HttpClient, AccessToken), AccessToken).GetAwaiter().GetResult();

            WriteObject(owners.OrderBy(o => o.DisplayName), true);
        }
 protected override void ExecuteCmdlet()
 {
     WriteObject(Microsoft365GroupsUtility.RestoreDeletedGroupAsync(HttpClient, Identity.GetDeletedGroupId(HttpClient, AccessToken), AccessToken).GetAwaiter().GetResult());
 }
        protected override void ExecuteCmdlet()
        {
            var group = Identity.GetGroup(HttpClient, AccessToken, false, false);


            if (group != null)
            {
                bool changed = false;
                if (ParameterSpecified(nameof(DisplayName)))
                {
                    group.DisplayName = DisplayName;
                    changed           = true;
                }
                if (ParameterSpecified(nameof(Description)))
                {
                    group.Description = Description;
                    changed           = true;
                }
                if (ParameterSpecified(nameof(IsPrivate)))
                {
                    group.Visibility = IsPrivate ? "Private" : "Public";
                    changed          = true;
                }
                if (changed)
                {
                    group = Microsoft365GroupsUtility.UpdateAsync(HttpClient, AccessToken, group).GetAwaiter().GetResult();
                }

                if (ParameterSpecified(nameof(Owners)))
                {
                    Microsoft365GroupsUtility.UpdateOwnersAsync(HttpClient, group.Id.Value, AccessToken, Owners).GetAwaiter().GetResult();
                }

                if (ParameterSpecified(nameof(Members)))
                {
                    Microsoft365GroupsUtility.UpdateMembersAsync(HttpClient, group.Id.Value, AccessToken, Members).GetAwaiter().GetResult();
                }

                if (ParameterSpecified(nameof(LogoPath)))
                {
                    if (!Path.IsPathRooted(LogoPath))
                    {
                        LogoPath = Path.Combine(SessionState.Path.CurrentFileSystemLocation.Path, LogoPath);
                    }
                    Microsoft365GroupsUtility.UploadLogoAsync(HttpClient, AccessToken, group.Id.Value, LogoPath).GetAwaiter().GetResult();
                }

                if (ParameterSpecified(nameof(CreateTeam)))
                {
                    if (!group.ResourceProvisioningOptions.Contains("Team"))
                    {
                        Microsoft365GroupsUtility.CreateTeamAsync(HttpClient, AccessToken, group.Id.Value).GetAwaiter().GetResult();
                    }
                    else
                    {
                        WriteWarning("There is already a provisioned Team for this group. Skipping Team creation.");
                    }
                }

                if (ParameterSpecified(nameof(HideFromAddressLists)) || ParameterSpecified(nameof(HideFromOutlookClients)))
                {
                    // For this scenario a separate call needs to be made
                    Microsoft365GroupsUtility.SetVisibilityAsync(HttpClient, AccessToken, group.Id.Value, HideFromAddressLists, HideFromOutlookClients).GetAwaiter().GetResult();
                }
            }
        }