2016-03-04 51 views
0

有没有办法让所有用户谁拥有在网站集和子级“完全控制”权限和改变自己的角色,其他的东西? PowerShell将是理想的,但CSOM也可以,如果这是唯一的方法。我知道我可以通过角色获得团体,但我需要一种方法来获得明确添加用户的SharePoint O365获取所有用户提供一定的作用

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

回答

0

根据错误信息,我怀疑凭据在代码中失踪。

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

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; 
    } 
} 
+0

谢谢Jeffrey!我不能相信我错过了这一点。 – StraighterSwing

相关问题