【问题标题】:SharePoint O365 Get All Users With Certain RoleSharePoint O365 获取具有特定角色的所有用户
【发布时间】:2016-06-18 12:38:21
【问题描述】:

有没有办法让在网站集和子网站级别拥有“完全控制”权限的所有用户,并将他们的角色更改为其他角色? PowerShell 将是理想的,但如果这是唯一的方法,CSOM 也会很好。我知道我可以按角色获取组,但我需要一种方法来获取明确添加的用户

我尝试了这个较旧的 StackOverflow 问题:Get all the users based on a specific permission using CSOM in SharePoint 2013,但在第一个 ctx.ExecuteQuery(); 上我不断收到 403 禁止错误;即使我是收藏管理员,也适用于所有网站。我也想知道是否有人有 PowerShell 方法来做到这一点。

【问题讨论】:

    标签: powershell sharepoint permissions office365 csom


    【解决方案1】:

    根据错误消息,我怀疑您的代码中缺少凭据。

    请尝试下面的代码,让我知道它是否适用于您。

        static void Main(string[] args)
        {
            var webUrl = "[your_site_url]";
    
            var userEmailAddress = "[your_email_address]";
    
            using (var context = new ClientContext(webUrl))
            {
                Console.WriteLine("input your password and click enter");
    
                context.Credentials = new SharePointOnlineCredentials(userEmailAddress, GetPasswordFromConsoleInput());
                context.Load(context.Web, w => w.Title);
                context.ExecuteQuery();
    
                Console.WriteLine("Your site title is: " + context.Web.Title);
    
                //Retrieve site users             
                var users = context.LoadQuery(context.Web.SiteUsers);
    
                context.ExecuteQuery();
    
                foreach(var user in users)
                {
                    Console.WriteLine(user.Email);
                }
            }
        }
    
        private static SecureString GetPasswordFromConsoleInput()
        {
            ConsoleKeyInfo info;
    
            SecureString securePassword = new SecureString();
            do
            {
                info = Console.ReadKey(true);
                if (info.Key != ConsoleKey.Enter)
                {
                    securePassword.AppendChar(info.KeyChar);
                }
            }
            while (info.Key != ConsoleKey.Enter);
    
            return securePassword;
        }
    }
    

    【讨论】:

    • 谢谢杰弗里!我不敢相信我错过了。
    【解决方案2】:

    您需要 SharePoint Online Management shell 才能通过 Powershell 建立与 O365 的连接。

    Introduction to the SharePoint Online management shell

    【讨论】:

    • 谢谢你,但我已经安装了。正如我在原始帖子中提到的那样,我可以成功更改组角色,而无需获取和\或设置用户角色。
    猜你喜欢
    • 2014-08-31
    • 1970-01-01
    • 2021-02-24
    • 2021-10-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-17
    • 1970-01-01
    相关资源
    最近更新 更多