Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

First of all, i want to apologize for my english :) Im just a french student.

I work on SP 2013 for 3 weeks now. I'm using it with powershell. I have to write a script that will create web app, sites collection, subsite on 2 levels, and finally document libraries. I have to set permissions for several users, on each library, in powershell.

The New-SPUser and Set-SPUser do not work with a library's url.

So I found things like this Add group to Library permissions using powershell.

EDIT : I succeeded in creating the good rights for my user on a document library which is not in a subsite.

So I thought I can do the same, by using Get-SPWeb instead of Get-SPSite, but no.

So I'm still not able to set permissions on a subsite's document library =/ and by the way, i can't add users/groups to set their permissions

share|improve this question
add comment

2 Answers

You have to break inheritance before you are able to change permissions for a SPWeb. Refer to this link.

share|improve this answer
    
Thanks for your reply. I've already done this, with $list.BreakRoleInheritance($true) –  Nico Jun 24 '13 at 13:18
    
Do you mean I have to do this for subsites ?? –  Nico Jun 24 '13 at 13:20
    
It depends on your requirements. In your example you broke inheritance at the list level only. If you needed to change permissions for a sub-site you would to the same for the respective SPWeb object. –  Miguel Lima Jun 24 '13 at 13:23
    
Hum ok, That's clever :D I think the problem comes from the fact that I have lists in subsites... And i want so set permissions for each lists. I'll test it asap, and post if I find something interesting. Thank you @Miguel Lima –  Nico Jun 24 '13 at 13:29
add comment
up vote 0 down vote accepted

I think i've found something interesting. I'll test it and come back if it's the solution : http://urlmin.com/qye

$web = Get-SPWeb http://sp-2010
$account = $web.EnsureUser("SHAREPOINT\mray")
$role = $web.RoleDefinitions["Contribute"]

$list = $web.Lists["Shared Documents"]

$list.BreakRoleInheritance($true)

$assignment = New-Object Microsoft.SharePoint.SPRoleAssignment($account)
$assignment.RoleDefinitionBindings.Add($role)
$list.RoleAssignments.Add($assignment)

$list.Update()
$web.Dispose()
share|improve this answer
    
It works perfectly ! Will accept it as an answer but tomorrow. Can't do it today ~.~ –  Nico Jun 25 '13 at 7:54
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.