有没有办法让所有在网站集和子网站级别拥有“完全控制”权限的用户将其角色更改为其他用户? PowerShell将是理想的,但如果这是唯一的方法,CSOM也会很好。 我知道我可以通过角色获得组,但我需要一种方法来明确添加用户 。
我尝试了这个较旧的StackOverflow问题: 在SharePoint 2013中使用CSOM获取基于特定权限的所有用户,但我在第一个ctx.ExecuteQuery()上不断收到403禁用错误; 对于所有网站,即使我是收藏管理员。 我也想知道是否有人有PowerShell方法来做到这一点。
Is there a way to get all users who have "Full Control" permission at a site collection and subsite level and change their role to something else? PowerShell would be ideal but CSOM would be fine too if that's the only way to do it. I know I can get groups by role but I need a way to get explicitly added users.
I tried this older StackOverflow question: Get all the users based on a specific permission using CSOM in SharePoint 2013 but I keep getting a 403 forbidden error on the first ctx.ExecuteQuery(); for all sites even though I am a collection administrator. I also wonder if anyone had a PowerShell way to do it.
最满意答案
根据错误消息,我怀疑您的代码中缺少凭据。
请尝试下面的代码,让我知道它是否适合您。
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; } }According the error message, I suspect that the credential is missing in your code.
Please try the code below and let me know whether it works on your side.
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; } }更多推荐
发布评论