Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Setup context
- $context=New-Object Microsoft.SharePoint.Client.ClientContext($siteUrl)
- $web=$context.Web
- # New user object
- $user=$web.EnsureUser("domainusername");
- # Role definition
- $rd = $web.RoleDefinitions.GetByName("Full Control")
- # Create role definition binding collection
- $rdbc=New-Object Microsoft.SharePoint.Client.RoleDefinitionBindingCollection($context)
- $context.ExecuteQuery();
- $rdbc.Add($rd)
- $context.Web.RoleAssignments.Add($user, $rdbc)
- $context.ExecuteQuery();
- public void Load<T>(
- T clientObject,
- params Expression<Func<T, Object>>[] retrievals
- )
- where T : ClientObject
- class Program
- {
- static void Main(string[] args)
- {
- ClientContext ctx = new ClientContext("http://domain-dev/");
- Web web = ctx.Web;
- ctx.Load(web);
- ctx.ExecuteQuery();
- Console.WriteLine(web.Title);
- User user = web.EnsureUser("domain\bdobbs");
- ctx.Load(user);
- ctx.ExecuteQuery();
- Console.WriteLine(user.Email);
- var rd = web.RoleDefinitions.GetByName("Full Control");
- ctx.Load(rd);
- ctx.ExecuteQuery();
- Console.WriteLine(rd.Description);
- RoleDefinitionBindingCollection rdbc = new RoleDefinitionBindingCollection(ctx);
- ctx.Load(rdbc);
- ctx.ExecuteQuery();
- rdbc.Add(rd);
- web.RoleAssignments.Add(user, rdbc);
- web.Update();
- ctx.ExecuteQuery();
- Console.Read();
- }
- }
- # Setup context
- $context=New-Object Microsoft.SharePoint.Client.ClientContext($siteUrl)
- $web=$context.Web
- //Load the $web object here.
- # New user object
- $user=$web.EnsureUser("domainusername");
- //load the $user object here.
- # Role definition
- $rd = $web.RoleDefinitions.GetByName("Full Control")
- # Create role definition binding collection
- $rdbc=New-Object Microsoft.SharePoint.Client.RoleDefinitionBindingCollection($context)
- //load the $rdbc object here.
- $context.ExecuteQuery();
- $rdbc.Add($rd)
- $context.Web.RoleAssignments.Add($user, $rdbc)
- $context.ExecuteQuery();
- Add-Type -Path "C:Program FilesCommon Filesmicrosoft sharedSharePoint ClientMicrosoft.SharePoint.Client.dll"
- Add-Type -Path "C:Program FilesCommon Filesmicrosoft sharedSharePoint ClientMicrosoft.SharePoint.Client.Runtime.dll"
- $Ctx = New-Object Microsoft.SharePoint.Client.ClientContext("SharePointSiteURL")
- $Web = $Ctx.Web
- $Ctx.Load($Web)
- $Ctx.ExecuteQuery()
- Write-Host $Web.Title
- $User = $Web.EnsureUser("domainUserID")
- $Ctx.Load($User)
- $Ctx.ExecuteQuery()
- Write-Host $User.Email
- $RD = $Web.RoleDefinitions.GetByName("Full Control")
- $Ctx.Load($RD)
- $Ctx.ExecuteQuery()
- Write-Host $RD.Description
- $RDBC = New-Object Microsoft.SharePoint.Client.RoleDefinitionBindingCollection($Ctx)
- $Ctx.Load($RDBC)
- $Ctx.ExecuteQuery()
- $RDBC.Add($RD)
- $ctx.Load($Web.RoleAssignments.Add($User, $RDBC))
- $Web.Update()
- $Ctx.ExecuteQuery()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement