0

I need to create a subfolder (in a SharePoint document library) without inheriting permissions from the parent folder. I then need to assign specific permissions to the newly created subfolder. What is the best way to go about doing this? Thank you.

I used PowerShell to create Folder A inside a SharePoint 2013 document library. I used PowerShell to create a subfolder of FolderA. This subfolder is named FolderB. I do not want FolderB to inherit any of FolderA's permissions. However, when I create FolderB, FolderB inherits all of FolderA's permissions. Is there a way to tell SharePoint not to apply FolderA's permission to FolderB when FolderB is created? Here is my code:

$FolderA = $list.AddItem("", [Microsoft.SharePoint.SPFileSystemObjectType]::Folder, "Folder A");
$FolderA.Update();
$FolderA.BreakRoleInheritance("true");
$FolderA.Update();
Write-Output "Folder created " $FolderA.Url


$FolderBURL=$list.ParentWebUrl +"/" + $FolderA.Url;
write-host $FolderBURL;
$FolderB = $list.AddItem($FolderBURL, [Microsoft.SharePoint.SPFileSystemObjectType]::Folder, "Folder B");
$FolderB.Update();
$FolderB.BreakRoleInheritance("true"); 
$FolderB.Update(); 

Thanks in advance.

2

When you use BreakRoleInheritance with $true or $false you do the following :

  • you are assigning the folder with unique permissions.
  • Any new permissions added to the item are only applied to the item.

Only the difference :

  • $true to copy role assignments from the parent object to this object;

  • $false to assign only the current user to security roles.

So For Folder A you can set BreakRoleInheritance to $true or remove the following two lines

 $FolderA.BreakRoleInheritance($true);
    $FolderA.Update();

For Folder B you should can set BreakRoleInheritance to $false

The final code should be

$FolderA = $list.AddItem("", [Microsoft.SharePoint.SPFileSystemObjectType]::Folder, "Folder A");
$FolderA.Update();
$FolderA.BreakRoleInheritance($true);
$FolderA.Update();
Write-Output "Folder created " $FolderA.Url


$FolderBURL=$list.ParentWebUrl +"/" + $FolderA.Url;
write-host $FolderBURL;
$FolderB = $list.AddItem($FolderBURL, [Microsoft.SharePoint.SPFileSystemObjectType]::Folder, "Folder B");
$FolderB.Update();
$FolderB.BreakRoleInheritance($false); 
$FolderB.Update(); 

Check also Syntax of BreakRoleInheritance

-1

Hope this helps

https://sharepoint.stackexchange.com/a/149089/57662

It will stop the inheritance but you will have to apply whatever permissions you want.

  • 1
    Please point out what part is differing in the answer from that link and the users code above – Robert Lindgren Aug 5 '16 at 7:48
  • $item.BreakRoleInheritance($false,$false) – user3271150 Aug 5 '16 at 8:33
  • so in this format;- $FolderB.BreakRoleInheritance($false,$false) – user3271150 Aug 5 '16 at 8:37
  • Your two last comments doesn't help much. They are different from each other, and don't have the same result. Instead - update your answer by hitting the edit button and explain what you really mean. Thank you! – Benny Skogberg Oct 25 '16 at 19:30
  • Benny what are you reading? my last 2 comments? I was asked to point out what differs, So I did. The answers do indeed differ. If I wrote more it would only detract from the answer. So agian the user has this;- $FolderB.BreakRoleInheritance($false); – user3271150 Oct 26 '16 at 9:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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