Esempio n. 1
0
        protected override void ExecuteCmdlet()
        {
            var groupId = Team.GetGroupId(HttpClient, AccessToken);

            if (groupId != null)
            {
                try
                {
                    if (ParameterSetName == ParamSet_ByUser)
                    {
                        TeamsUtility.AddUserAsync(HttpClient, AccessToken, groupId, User, Role).GetAwaiter().GetResult();
                    }
                    else
                    {
                        TeamsUtility.AddUsersAsync(HttpClient, AccessToken, groupId, Users, Role).GetAwaiter().GetResult();
                    }
                }
                catch (GraphException ex)
                {
                    if (ex.Error != null)
                    {
                        throw new PSInvalidOperationException(ex.Error.Message);
                    }
                    else
                    {
                        throw;
                    }
                }
            }
            else
            {
                throw new PSArgumentException("Group not found");
            }
        }
Esempio n. 2
0
 public TeamTab GetTab(BasePSCmdlet cmdlet, HttpClient httpClient, string accessToken, string groupId, string channelId)
 {
     if (_tab != null)
     {
         return(_tab);
     }
     else
     {
         var tab = TeamsUtility.GetTabAsync(accessToken, httpClient, groupId, channelId, _id).GetAwaiter().GetResult();
         if (string.IsNullOrEmpty(tab.Id))
         {
             var tabs = TeamsUtility.GetTabsAsync(accessToken, httpClient, groupId, channelId).GetAwaiter().GetResult();
             if (tabs != null)
             {
                 // find the tab by id
                 tab = tabs.FirstOrDefault(t => t.DisplayName.Equals(_displayName, System.StringComparison.OrdinalIgnoreCase));
             }
         }
         if (tab != null)
         {
             return(tab);
         }
         else
         {
             cmdlet.WriteError(new PSArgumentException("Cannot find tab"), ErrorCategory.ObjectNotFound);
             return(null);
         }
     }
 }
Esempio n. 3
0
        protected override void ExecuteCmdlet()
        {
            var groupId = Team.GetGroupId(HttpClient, AccessToken);

            if (groupId != null)
            {
                var channel = Channel.GetChannel(HttpClient, AccessToken, groupId);
                if (channel != null)
                {
                    var channelMessage = new TeamChannelMessage();
                    channelMessage.Importance       = Important ? "high" : "normal";
                    channelMessage.Body.Content     = Message;
                    channelMessage.Body.ContentType = ContentType == TeamChannelMessageContentType.Html ? "html" : "text";

                    TeamsUtility.PostMessageAsync(HttpClient, AccessToken, groupId, channel.Id, channelMessage).GetAwaiter().GetResult();
                }
                else
                {
                    throw new PSArgumentException("Channel not found");
                }
            }
            else
            {
                throw new PSArgumentException("Team not found");
            }
        }
 public TeamTab GetTab(HttpClient httpClient, string accessToken, string groupId, string channelId)
 {
     if (_tab != null)
     {
         return _tab;
     }
     else
     {
         var tab = TeamsUtility.GetTab(accessToken, httpClient, groupId, channelId, _id);
         if (string.IsNullOrEmpty(tab.Id))
         {
             var tabs = TeamsUtility.GetTabs(accessToken, httpClient, groupId, channelId);
             if (tabs != null)
             {
                 // find the tab by id
                 tab = tabs.FirstOrDefault(t => t.DisplayName.Equals(_displayName, System.StringComparison.OrdinalIgnoreCase));
             }
         }
         if (tab != null)
         {
             return tab;
         }
         else
         {
             throw new PSArgumentException("Cannot find tab");
         }
     }
 }
Esempio n. 5
0
        protected override void ExecuteCmdlet()
        {
            if (!System.IO.Path.IsPathRooted(Path))
            {
                Path = System.IO.Path.Combine(SessionState.Path.CurrentFileSystemLocation.Path, Path);
            }

            if (System.IO.File.Exists(Path))
            {
                try
                {
                    var bytes = System.IO.File.ReadAllBytes(Path);
                    TeamsUtility.AddAppAsync(HttpClient, AccessToken, bytes).GetAwaiter().GetResult();
                }
                catch (GraphException ex)
                {
                    if (ex.Error != null)
                    {
                        throw new PSInvalidOperationException(ex.Error.Message);
                    }
                    else
                    {
                        throw new PSInvalidOperationException(ex.Message);
                    }
                }
            }
            else
            {
                new PSArgumentException("File not found");
            }
        }
Esempio n. 6
0
        protected override void ExecuteCmdlet()
        {
            var groupId = Team.GetGroupId(HttpClient, AccessToken);

            if (groupId != null)
            {
                try
                {
                    var channel = TeamsUtility.AddChannelAsync(AccessToken, HttpClient, groupId, DisplayName, Description, Private, OwnerUPN).GetAwaiter().GetResult();
                    WriteObject(channel);
                }
                catch (GraphException ex)
                {
                    if (ex.Error != null)
                    {
                        throw new PSInvalidOperationException(ex.Error.Message);
                    }
                    else
                    {
                        throw ex;
                    }
                }
            }
            else
            {
                throw new PSArgumentException("Group not found");
            }
        }
Esempio n. 7
0
        protected override void ExecuteCmdlet()
        {
            var groupId = Team.GetGroupId(HttpClient, AccessToken);

            if (groupId != null)
            {
                try
                {
                    WriteObject(TeamsUtility.GetUsers(HttpClient, AccessToken, groupId, Role), true);
                }
                catch (GraphException ex)
                {
                    if (ex.Error != null)
                    {
                        throw new PSInvalidOperationException(ex.Error.Message);
                    }
                    else
                    {
                        throw ex;
                    }
                }
            }
            else
            {
                throw new PSArgumentException("Group not found");
            }
        }
Esempio n. 8
0
        protected override void ExecuteCmdlet()
        {
            var groupId = Team.GetGroupId(HttpClient, AccessToken);

            if (groupId != null)
            {
                var channelId = Channel.GetId(HttpClient, AccessToken, groupId);
                if (channelId != null)
                {
                    var tab = Identity.GetTab(HttpClient, AccessToken, groupId, channelId);
                    if (tab != null)
                    {
                        if (ParameterSpecified(nameof(DisplayName)) && tab.DisplayName != DisplayName)
                        {
                            tab.DisplayName = DisplayName;
                        }
                        TeamsUtility.UpdateTabAsync(HttpClient, AccessToken, groupId, channelId, tab).GetAwaiter().GetResult();
                    }
                    else
                    {
                        throw new PSArgumentException("Tab not found");
                    }
                }
                else
                {
                    throw new PSArgumentException("Channel not found");
                }
            }
            else
            {
                throw new PSArgumentException("Team not found");
            }
        }
Esempio n. 9
0
        protected override void ExecuteCmdlet()
        {
            var teamCI = new TeamCreationInformation()
            {
                AllowAddRemoveApps                = AllowAddRemoveApps,
                AllowChannelMentions              = AllowChannelMentions,
                AllowCreateUpdateChannels         = AllowCreateUpdateChannels,
                AllowCreateUpdateRemoveConnectors = AllowCreateUpdateRemoveConnectors,
                AllowCreateUpdateRemoveTabs       = AllowCreateUpdateRemoveTabs,
                AllowCustomMemes               = AllowCustomMemes,
                AllowDeleteChannels            = AllowDeleteChannels,
                AllowGiphy                     = AllowGiphy,
                AllowGuestCreateUpdateChannels = AllowGuestCreateUpdateChannels,
                AllowGuestDeleteChannels       = AllowGuestDeleteChannels,
                AllowOwnerDeleteMessages       = AllowOwnerDeleteMessages,
                AllowStickersAndMemes          = AllowStickersAndMemes,
                AllowTeamMentions              = AllowTeamMentions,
                AllowUserDeleteMessages        = AllowUserDeleteMessages,
                AllowUserEditMessages          = AllowUserEditMessages,
                Classification                 = Classification,
                Description                    = Description,
                DisplayName                    = DisplayName,
                GiphyContentRating             = GiphyContentRating,
                GroupId = GroupId,
                ShowInTeamsSearchAndSuggestions = ShowInTeamsSearchAndSuggestions,
                Visibility = (GroupVisibility)Enum.Parse(typeof(GroupVisibility), Visibility.ToString()),
                AllowCreatePrivateChannels = AllowCreatePrivateChannels,
            };

            WriteObject(TeamsUtility.NewTeamAsync(AccessToken, HttpClient, GroupId, DisplayName, Description, Classification, MailNickName, Owner, (GroupVisibility)Enum.Parse(typeof(GroupVisibility), Visibility.ToString()), teamCI, Template, ResourceBehaviorOptions).GetAwaiter().GetResult());
        }
Esempio n. 10
0
        protected override void ExecuteCmdlet()
        {
            var groupId = Identity.GetGroupId(HttpClient, AccessToken);

            if (groupId != null)
            {
                if (Force || ShouldContinue("Removing the team will remove all messages in all channels in the team.", Properties.Resources.Confirm))
                {
                    var response = TeamsUtility.DeleteTeamAsync(AccessToken, HttpClient, groupId).GetAwaiter().GetResult();
                    if (!response.IsSuccessStatusCode)
                    {
                        if (GraphHelper.TryGetGraphException(response, out GraphException ex))
                        {
                            if (ex.Error != null)
                            {
                                throw new PSInvalidOperationException(ex.Error.Message);
                            }
                        }
                        else
                        {
                            WriteError(new ErrorRecord(new Exception($"Team remove failed"), "REMOVEFAILED", ErrorCategory.InvalidResult, this));
                        }
                    }
                }
            }
            else
            {
                throw new PSArgumentException("Team not found");
            }
        }
Esempio n. 11
0
        protected override void ExecuteCmdlet()
        {
            var groupId = Team.GetGroupId(HttpClient, AccessToken);

            if (groupId != null)
            {
                var channelId = Channel.GetId(HttpClient, AccessToken, groupId);
                if (!string.IsNullOrEmpty(channelId))
                {
                    if (ParameterSpecified(nameof(Identity)))
                    {
                        WriteObject(Identity.GetTab(HttpClient, AccessToken, groupId, channelId));
                    }
                    else
                    {
                        WriteObject(TeamsUtility.GetTabsAsync(AccessToken, HttpClient, groupId, channelId).GetAwaiter().GetResult(), true);
                    }
                }
                else
                {
                    throw new PSArgumentException("Channel not found");
                }
            }
            else
            {
                throw new PSArgumentException("Team not found");
            }
        }
Esempio n. 12
0
        protected override void ExecuteCmdlet()
        {
            Model.Teams.TeamChannel channel = null;

            var groupId = Team.GetGroupId(HttpClient, AccessToken);

            if (groupId != null)
            {
                try
                {
                    TeamsUtility.AddUser(HttpClient, AccessToken, groupId, User, Role);
                    WriteObject(channel);
                }
                catch (GraphException ex)
                {
                    if (ex.Error != null)
                    {
                        throw new PSInvalidOperationException(ex.Error.Message);
                    }
                    else
                    {
                        throw ex;
                    }
                }
            }
            else
            {
                throw new PSArgumentException("Group not found");
            }
        }
Esempio n. 13
0
        protected override void ExecuteCmdlet()
        {
            var groupId = Team.GetGroupId(HttpClient, AccessToken);

            if (groupId != null)
            {
                try
                {
                    if (Force || ShouldContinue($"Remove user with UPN {User}?", Properties.Resources.Confirm))
                    {
                        TeamsUtility.DeleteUserAsync(HttpClient, AccessToken, groupId, User, Role).GetAwaiter().GetResult();
                    }
                }
                catch (GraphException ex)
                {
                    if (ex.Error != null)
                    {
                        throw new PSInvalidOperationException(ex.Error.Message);
                    }
                    else
                    {
                        throw ex;
                    }
                }
            }
            else
            {
                throw new PSArgumentException("Group not found");
            }
        }
Esempio n. 14
0
        protected override void ExecuteCmdlet()
        {
            var app = Identity.GetApp(HttpClient, AccessToken);

            if (app == null)
            {
                throw new PSArgumentException("App not found");
            }
            if (Force || ShouldContinue($"Do you want to remove {app.DisplayName}?", Properties.Resources.Confirm))
            {
                var response = TeamsUtility.DeleteAppAsync(HttpClient, AccessToken, app.Id).GetAwaiter().GetResult();
                if (!response.IsSuccessStatusCode)
                {
                    if (GraphHelper.TryGetGraphException(response, out GraphException ex))
                    {
                        if (ex.Error != null)
                        {
                            throw new PSInvalidOperationException(ex.Error.Message);
                        }
                    }
                    else
                    {
                        throw new PSInvalidOperationException("Removing app failed");
                    }
                }
                else
                {
                    WriteObject("App removed");
                }
            }
        }
Esempio n. 15
0
        protected override void ExecuteCmdlet()
        {
            var groupId = Team.GetGroupId(HttpClient, AccessToken);

            if (groupId != null)
            {
                var channelId = Channel.GetId(HttpClient, AccessToken, groupId);
                if (channelId != null)
                {
                    var tabId = string.Empty;
                    if (string.IsNullOrEmpty(Identity.Id))
                    {
                        tabId = Identity.Id.ToString();
                    }
                    else
                    {
                        var tab = Identity.GetTab(HttpClient, AccessToken, groupId, channelId);
                        if (tab != null)
                        {
                            tabId = tab.Id;
                        }
                        else
                        {
                            throw new PSArgumentException("Cannot find tab");
                        }
                    }
                    if (Force || ShouldContinue("Removing the tab will remove the settings of this tab too.", Properties.Resources.Confirm))
                    {
                        var response = TeamsUtility.DeleteTab(AccessToken, HttpClient, groupId, channelId, tabId);
                        if (!response.IsSuccessStatusCode)
                        {
                            if (GraphHelper.TryGetGraphException(response, out GraphException ex))
                            {
                                if (ex.Error != null)
                                {
                                    throw new PSInvalidOperationException(ex.Error.Message);
                                }
                            }
                            else
                            {
                                throw new PSInvalidOperationException("Tab remove failed");
                            }
                        }
                    }
                }
                else
                {
                    throw new PSArgumentException("Channel not found");
                }
            }
            else
            {
                throw new PSArgumentException("Team not found", nameof(Team));
            }
        }
 public string GetId(HttpClient httpClient, string accessToken, string groupId)
 {
     if (!string.IsNullOrEmpty(_id))
     {
         return(_id);
     }
     else
     {
         var channels = TeamsUtility.GetChannelsAsync(accessToken, httpClient, groupId).GetAwaiter().GetResult();
         return(channels.FirstOrDefault(c => c.DisplayName.Equals(_displayName, StringComparison.OrdinalIgnoreCase)).Id);
     }
 }
Esempio n. 17
0
        protected override void ExecuteCmdlet()
        {
            var groupId = Team.GetGroupId(HttpClient, AccessToken);

            if (groupId != null)
            {
                var teamChannel = Identity.GetChannel(HttpClient, AccessToken, groupId);
                if (teamChannel != null)
                {
                    if (ParameterSpecified(nameof(DisplayName)) && teamChannel.DisplayName != DisplayName)
                    {
                        teamChannel.DisplayName = DisplayName;
                    }
                    else
                    {
                        teamChannel.DisplayName = null;
                    }
                    if (ParameterSpecified(nameof(Description)) && teamChannel.Description != Description)
                    {
                        teamChannel.Description = Description;
                    }
                    else
                    {
                        teamChannel.Description = null;
                    }
                    teamChannel.MembershipType = null;
                    try
                    {
                        var updated = TeamsUtility.UpdateChannel(HttpClient, AccessToken, groupId, teamChannel.Id, teamChannel);
                        WriteObject(updated);
                    }
                    catch (GraphException ex)
                    {
                        if (ex.Error != null)
                        {
                            throw new PSInvalidOperationException(ex.Error.Message);
                        }
                        else
                        {
                            throw ex;
                        }
                    }
                }
                else
                {
                    throw new PSArgumentException("Channel not found");
                }
            }
            else
            {
                throw new PSArgumentException("Group not found");
            }
        }
Esempio n. 18
0
 protected override void ExecuteCmdlet()
 {
     if (ParameterSpecified(nameof(Identity)))
     {
         var groupId = Identity.GetGroupId(HttpClient, AccessToken);
         if (groupId != null)
         {
             WriteObject(TeamsUtility.GetTeamAsync(AccessToken, HttpClient, groupId).GetAwaiter().GetResult());
         }
     }
     else
     {
         WriteObject(TeamsUtility.GetTeamsAsync(AccessToken, HttpClient).GetAwaiter().GetResult(), true);
     }
 }
Esempio n. 19
0
 protected override void ExecuteCmdlet()
 {
     if (ParameterSpecified(nameof(Identity)))
     {
         var app = Identity.GetApp(HttpClient, AccessToken);
         if (app != null)
         {
             WriteObject(app);
         }
     }
     else
     {
         WriteObject(TeamsUtility.GetAppsAsync(AccessToken, HttpClient).GetAwaiter().GetResult(), true);
     }
 }
Esempio n. 20
0
        protected override void ExecuteCmdlet()
        {
            var groupId = Team.GetGroupId(HttpClient, AccessToken);

            if (groupId != null)
            {
                try
                {
                    if (ParameterSpecified(nameof(Channel)))
                    {
                        var teamChannels = TeamsUtility.GetChannelsAsync(AccessToken, HttpClient, groupId).GetAwaiter().GetResult();

                        var channelId = Channel.GetId(HttpClient, AccessToken, groupId);

                        var requestedChannel = teamChannels.FirstOrDefault(c => c.Id == channelId);

                        if (!string.IsNullOrEmpty(channelId) && requestedChannel != null && requestedChannel.MembershipType.ToLower() == TeamChannelType.Private.ToString().ToLower())
                        {
                            WriteObject(TeamsUtility.GetUsersAsync(HttpClient, AccessToken, groupId, channelId, Role).GetAwaiter().GetResult(), true);
                        }
                        else
                        {
                            WriteWarning("Specified channel is not a private channel. Please specify a private channel name to fetch its users.");
                        }
                    }
                    else
                    {
                        WriteObject(TeamsUtility.GetUsersAsync(HttpClient, AccessToken, groupId, Role).GetAwaiter().GetResult(), true);
                    }
                }
                catch (GraphException ex)
                {
                    if (ex.Error != null)
                    {
                        throw new PSInvalidOperationException(ex.Error.Message);
                    }
                    else
                    {
                        throw;
                    }
                }
            }
            else
            {
                throw new PSArgumentException("Group not found");
            }
        }
Esempio n. 21
0
        public TeamChannel GetChannel(HttpClient httpClient, string accessToken, string groupId)
        {
            var channels = TeamsUtility.GetChannels(accessToken, httpClient, groupId);

            if (channels != null && channels.Any())
            {
                if (!string.IsNullOrEmpty(_id))
                {
                    return(channels.FirstOrDefault(c => c.Id.Equals(_id, StringComparison.OrdinalIgnoreCase)));
                }
                else
                {
                    return(channels.FirstOrDefault(c => c.DisplayName.Equals(_displayName, StringComparison.OrdinalIgnoreCase)));
                }
            }
            return(null);
        }
Esempio n. 22
0
        protected override void ExecuteCmdlet()
        {
            var groupId = Team.GetGroupId(HttpClient, AccessToken);

            if (groupId != null)
            {
                if (!System.IO.Path.IsPathRooted(Path))
                {
                    Path = System.IO.Path.Combine(SessionState.Path.CurrentFileSystemLocation.Path, Path);
                }
                if (System.IO.File.Exists(Path))
                {
                    var contentType = "";
                    var fileInfo    = new FileInfo(Path);
                    switch (fileInfo.Extension)
                    {
                    case ".jpg":
                    case ".jpeg":
                    {
                        contentType = "image/jpeg";
                        break;
                    }

                    case ".png":
                    {
                        contentType = "image/png";
                        break;
                    }
                    }
                    if (string.IsNullOrEmpty(contentType))
                    {
                        throw new PSArgumentException("File is not of a supported content type (jpg/png)");
                    }
                    var byteArray = System.IO.File.ReadAllBytes(Path);
                    TeamsUtility.SetTeamPictureAsync(HttpClient, AccessToken, groupId, byteArray, contentType).GetAwaiter().GetResult();
                }
                else
                {
                    throw new PSArgumentException("File not found");
                }
            }
            else
            {
                throw new PSArgumentException("Team not found");
            }
        }
Esempio n. 23
0
 protected override void ExecuteCmdlet()
 {
     if (ParameterSpecified(nameof(Identity)))
     {
         var groupId = Identity.GetGroupId(HttpClient, AccessToken);
         if (groupId != null)
         {
             WriteObject(TeamsUtility.GetTeamAsync(AccessToken, HttpClient, groupId).GetAwaiter().GetResult());
         }
         else
         {
             WriteError(new PSArgumentException("Team not found"), ErrorCategory.ObjectNotFound);
         }
     }
     else
     {
         WriteObject(TeamsUtility.GetTeamsAsync(AccessToken, HttpClient).GetAwaiter().GetResult(), true);
     }
 }
Esempio n. 24
0
 protected override void ExecuteCmdlet()
 {
     if (ParameterSpecified(nameof(Identity)))
     {
         var groupId = Identity.GetGroupId(HttpClient, AccessToken);
         if (groupId != null)
         {
             WriteObject(TeamsUtility.GetTeam(AccessToken, HttpClient, groupId));
         }
         else
         {
             throw new PSArgumentException("Team not found");
         }
     }
     else
     {
         WriteObject(TeamsUtility.GetTeams(AccessToken, HttpClient), true);
     }
 }
Esempio n. 25
0
        protected override void ExecuteCmdlet()
        {
            var groupId = Team.GetGroupId(HttpClient, AccessToken);

            if (groupId != null)
            {
                if (ParameterSpecified(nameof(Identity)))
                {
                    WriteObject(Identity.GetChannel(HttpClient, AccessToken, groupId));
                }
                else
                {
                    WriteObject(TeamsUtility.GetChannelsAsync(AccessToken, HttpClient, groupId).GetAwaiter().GetResult());
                }
            }
            else
            {
                throw new PSArgumentException("Team not found", nameof(Team));
            }
        }
        protected override void ExecuteCmdlet()
        {
            var groupId = Team.GetGroupId(HttpClient, AccessToken);

            if (groupId != null)
            {
                var channel = Channel.GetChannel(HttpClient, AccessToken, groupId);
                if (channel != null)
                {
                    WriteObject(TeamsUtility.GetMessagesAsync(HttpClient, AccessToken, groupId, channel.Id, IncludeDeleted).GetAwaiter().GetResult(), true);
                }
                else
                {
                    throw new PSArgumentException("Channel not found");
                }
            }
            else
            {
                throw new PSArgumentException("Team not found");
            }
        }
Esempio n. 27
0
        protected override void ExecuteCmdlet()
        {
            if (!System.IO.Path.IsPathRooted(Path))
            {
                Path = System.IO.Path.Combine(SessionState.Path.CurrentFileSystemLocation.Path, Path);
            }

            if (System.IO.File.Exists(Path))
            {
                var app = Identity.GetApp(HttpClient, AccessToken);
                if (app != null)
                {
                    var bytes    = System.IO.File.ReadAllBytes(Path);
                    var response = TeamsUtility.UpdateAppAsync(HttpClient, AccessToken, bytes, app.Id).GetAwaiter().GetResult();
                    if (!response.IsSuccessStatusCode)
                    {
                        if (GraphHelper.TryGetGraphException(response, out GraphException ex))
                        {
                            throw new PSInvalidOperationException(ex.Error.Message);
                        }
                        else
                        {
                            throw new PSInvalidOperationException("Update app failed");
                        }
                    }
                    else
                    {
                        WriteObject("App updated");
                    }
                }
                else
                {
                    throw new PSArgumentException("App not found");
                }
            }
            else
            {
                throw new PSArgumentException("File not found");
            }
        }
        protected override void ExecuteCmdlet()
        {
            if (!Archived && SetSiteReadOnlyForMembers.HasValue)
            {
                throw new PSArgumentException("You can only modify the read only state of a site when archiving a team");
            }
            var groupId = Identity.GetGroupId(HttpClient, AccessToken);

            if (groupId != null)
            {
                var team = Identity.GetTeam(HttpClient, AccessToken);
                if (Archived == team.IsArchived)
                {
                    throw new PSInvalidOperationException($"Team {team.DisplayName} {(Archived ? "has already been" : "is not")} archived");
                }
                var response = TeamsUtility.SetTeamArchivedStateAsync(HttpClient, AccessToken, groupId, Archived, SetSiteReadOnlyForMembers).GetAwaiter().GetResult();
                if (!response.IsSuccessStatusCode)
                {
                    if (GraphHelper.TryGetGraphException(response, out GraphException ex))
                    {
                        if (ex.Error != null)
                        {
                            throw new PSInvalidOperationException(ex.Error.Message);
                        }
                    }
                    else
                    {
                        throw new PSInvalidOperationException("Setting archived state failed.");
                    }
                }
                else
                {
                    WriteObject($"Team {(Archived ? "archived" : "unarchived")}.");
                }
            }
            else
            {
                throw new PSArgumentException("Team not found");
            }
        }
Esempio n. 29
0
        protected override void ExecuteCmdlet()
        {
            var groupId = Team.GetGroupId(HttpClient, AccessToken);

            if (groupId != null)
            {
                try
                {
                    if (ParameterSpecified(nameof(Channel)))
                    {
                        var channelId = Channel.GetId(HttpClient, AccessToken, groupId);
                        if (!string.IsNullOrEmpty(channelId))
                        {
                            WriteObject(TeamsUtility.GetUsersAsync(HttpClient, AccessToken, groupId, channelId, Role).GetAwaiter().GetResult(), true);
                        }
                    }
                    else
                    {
                        WriteObject(TeamsUtility.GetUsersAsync(HttpClient, AccessToken, groupId, Role).GetAwaiter().GetResult(), true);
                    }
                }
                catch (GraphException ex)
                {
                    if (ex.Error != null)
                    {
                        throw new PSInvalidOperationException(ex.Error.Message);
                    }
                    else
                    {
                        throw;
                    }
                }
            }
            else
            {
                throw new PSArgumentException("Group not found");
            }
        }
Esempio n. 30
0
        protected override void ExecuteCmdlet()
        {
            var groupId = Identity.GetGroupId(HttpClient, AccessToken);

            if (groupId != null)
            {
                try
                {
                    var team        = TeamsUtility.GetTeamAsync(AccessToken, HttpClient, groupId).GetAwaiter().GetResult();
                    var updateGroup = false;
                    var group       = new Group();
                    if (team != null)
                    {
                        if (ParameterSpecified(nameof(DisplayName)) && team.DisplayName != DisplayName)
                        {
                            updateGroup       = true;
                            group.DisplayName = DisplayName;
                        }
                        else
                        {
                            team.DisplayName = null;
                        }
                        if (ParameterSpecified(nameof(Description)) && team.Description != Description)
                        {
                            updateGroup       = true;
                            group.Description = Description;
                        }
                        else
                        {
                            team.Description = null;
                        }
                        if (ParameterSpecified(nameof(Visibility)) && (GroupVisibility)Enum.Parse(typeof(GroupVisibility), Visibility.ToString()) != team.Visibility)
                        {
                            group.Visibility = (GroupVisibility)Enum.Parse(typeof(GroupVisibility), Visibility.ToString());
                            updateGroup      = true;
                        }
                        team.IsArchived = null; // cannot update this value;

                        if (updateGroup)
                        {
                            TeamsUtility.UpdateGroupAsync(HttpClient, AccessToken, groupId, group).GetAwaiter().GetResult();
                        }

                        var teamCI = new TeamCreationInformation();
                        teamCI.AllowAddRemoveApps                = ParameterSpecified(nameof(AllowAddRemoveApps)) ? AllowAddRemoveApps : null;
                        teamCI.AllowChannelMentions              = ParameterSpecified(nameof(AllowChannelMentions)) ? AllowChannelMentions : null;
                        teamCI.AllowCreateUpdateChannels         = ParameterSpecified(nameof(AllowCreateUpdateChannels)) ? AllowCreateUpdateChannels : null;
                        teamCI.AllowCreateUpdateRemoveConnectors = ParameterSpecified(nameof(AllowCreateUpdateRemoveConnectors)) ? AllowCreateUpdateRemoveConnectors : null;
                        teamCI.AllowCreateUpdateRemoveTabs       = ParameterSpecified(nameof(AllowCreateUpdateRemoveTabs)) ? AllowCreateUpdateRemoveTabs : null;
                        teamCI.AllowCustomMemes               = ParameterSpecified(nameof(AllowCustomMemes)) ? AllowCustomMemes : null;
                        teamCI.AllowDeleteChannels            = ParameterSpecified(nameof(AllowDeleteChannels)) ? AllowDeleteChannels : null;
                        teamCI.AllowGiphy                     = ParameterSpecified(nameof(AllowGiphy)) ? AllowGiphy : null;
                        teamCI.AllowGuestCreateUpdateChannels = ParameterSpecified(nameof(AllowGuestCreateUpdateChannels)) ? AllowGuestCreateUpdateChannels : null;
                        teamCI.AllowGuestDeleteChannels       = ParameterSpecified(nameof(AllowGuestDeleteChannels)) ? AllowGuestDeleteChannels : null;
                        teamCI.AllowOwnerDeleteMessages       = ParameterSpecified(nameof(AllowOwnerDeleteMessages)) ? AllowOwnerDeleteMessages : null;
                        teamCI.AllowStickersAndMemes          = ParameterSpecified(nameof(AllowStickersAndMemes)) ? AllowStickersAndMemes : null;
                        teamCI.AllowTeamMentions              = ParameterSpecified(nameof(AllowTeamMentions)) ? AllowTeamMentions : null;
                        teamCI.AllowUserDeleteMessages        = ParameterSpecified(nameof(AllowUserDeleteMessages)) ? AllowUserDeleteMessages : null;
                        teamCI.AllowUserEditMessages          = ParameterSpecified(nameof(AllowUserEditMessages)) ? AllowUserEditMessages : null;
                        teamCI.Classification                 = ParameterSpecified(nameof(Classification)) ? Classification : null;

                        var updated = TeamsUtility.UpdateTeamAsync(HttpClient, AccessToken, groupId, teamCI.ToTeam()).GetAwaiter().GetResult();
                        WriteObject(updated);
                    }
                }
                catch (GraphException ex)
                {
                    if (ex.Error != null)
                    {
                        throw new PSInvalidOperationException(ex.Error.Message);
                    }
                    else
                    {
                        throw;
                    }
                }
            }
            else
            {
                throw new PSArgumentException("Team not found");
            }
        }