Advertisement
Guest User

Untitled

a guest
Jan 8th, 2016
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.90 KB | None | 0 0
  1. # Setup context
  2. $context=New-Object Microsoft.SharePoint.Client.ClientContext($siteUrl)
  3. $web=$context.Web
  4.  
  5. # New user object
  6. $user=$web.EnsureUser("domainusername");
  7.  
  8. # Role definition
  9. $rd = $web.RoleDefinitions.GetByName("Full Control")
  10.  
  11. # Create role definition binding collection
  12. $rdbc=New-Object Microsoft.SharePoint.Client.RoleDefinitionBindingCollection($context)
  13. $context.ExecuteQuery();
  14. $rdbc.Add($rd)
  15.  
  16. $context.Web.RoleAssignments.Add($user, $rdbc)
  17.  
  18. $context.ExecuteQuery();
  19.  
  20. public void Load<T>(
  21. T clientObject,
  22. params Expression<Func<T, Object>>[] retrievals
  23. )
  24. where T : ClientObject
  25.  
  26. class Program
  27. {
  28. static void Main(string[] args)
  29. {
  30. ClientContext ctx = new ClientContext("http://domain-dev/");
  31. Web web = ctx.Web;
  32. ctx.Load(web);
  33. ctx.ExecuteQuery();
  34. Console.WriteLine(web.Title);
  35.  
  36. User user = web.EnsureUser("domain\bdobbs");
  37. ctx.Load(user);
  38. ctx.ExecuteQuery();
  39.  
  40. Console.WriteLine(user.Email);
  41.  
  42. var rd = web.RoleDefinitions.GetByName("Full Control");
  43. ctx.Load(rd);
  44. ctx.ExecuteQuery();
  45.  
  46. Console.WriteLine(rd.Description);
  47.  
  48. RoleDefinitionBindingCollection rdbc = new RoleDefinitionBindingCollection(ctx);
  49. ctx.Load(rdbc);
  50. ctx.ExecuteQuery();
  51.  
  52. rdbc.Add(rd);
  53. web.RoleAssignments.Add(user, rdbc);
  54. web.Update();
  55. ctx.ExecuteQuery();
  56.  
  57. Console.Read();
  58.  
  59.  
  60. }
  61. }
  62.  
  63. # Setup context
  64. $context=New-Object Microsoft.SharePoint.Client.ClientContext($siteUrl)
  65. $web=$context.Web
  66.  
  67. //Load the $web object here.
  68.  
  69. # New user object
  70. $user=$web.EnsureUser("domainusername");
  71.  
  72. //load the $user object here.
  73.  
  74. # Role definition
  75. $rd = $web.RoleDefinitions.GetByName("Full Control")
  76.  
  77. # Create role definition binding collection
  78. $rdbc=New-Object Microsoft.SharePoint.Client.RoleDefinitionBindingCollection($context)
  79.  
  80. //load the $rdbc object here.
  81.  
  82. $context.ExecuteQuery();
  83.  
  84. $rdbc.Add($rd)
  85.  
  86. $context.Web.RoleAssignments.Add($user, $rdbc)
  87.  
  88. $context.ExecuteQuery();
  89.  
  90. Add-Type -Path "C:Program FilesCommon Filesmicrosoft sharedSharePoint ClientMicrosoft.SharePoint.Client.dll"
  91. Add-Type -Path "C:Program FilesCommon Filesmicrosoft sharedSharePoint ClientMicrosoft.SharePoint.Client.Runtime.dll"
  92.  
  93. $Ctx = New-Object Microsoft.SharePoint.Client.ClientContext("SharePointSiteURL")
  94.  
  95. $Web = $Ctx.Web
  96.  
  97. $Ctx.Load($Web)
  98. $Ctx.ExecuteQuery()
  99. Write-Host $Web.Title
  100.  
  101. $User = $Web.EnsureUser("domainUserID")
  102. $Ctx.Load($User)
  103. $Ctx.ExecuteQuery()
  104. Write-Host $User.Email
  105.  
  106. $RD = $Web.RoleDefinitions.GetByName("Full Control")
  107. $Ctx.Load($RD)
  108. $Ctx.ExecuteQuery()
  109. Write-Host $RD.Description
  110.  
  111. $RDBC = New-Object Microsoft.SharePoint.Client.RoleDefinitionBindingCollection($Ctx)
  112. $Ctx.Load($RDBC)
  113. $Ctx.ExecuteQuery()
  114.  
  115. $RDBC.Add($RD)
  116. $ctx.Load($Web.RoleAssignments.Add($User, $RDBC))
  117. $Web.Update()
  118. $Ctx.ExecuteQuery()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement