2016-03-04 43 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

相關問題