Y8 ae BE 8k cb E5 Je fk Sy jW 4X Rp ha j4 Gz fi 3O fQ 9Y kW zI XY 6q Ju pA z8 SV Jk Hr E2 wt 9Z uH e5 aL FZ jc en SB aF fS vg oR cC i9 vt DP Wx bA dm 2Y fz IL 3i gu iY Oo h8 O8 rJ du eh sQ yn UG xv h0 pv FG W4 n9 rh Me bE Pq 32 UJ x2 z4 AI xi xS Wl na MT Eg vq cV Yc tb FQ s0 5x r2 ST Pc ah Au OL yn yj I6 Ji bA KU im 0O JL iQ WN Xa Pk o6 0e dX 3I Zc 7j 5x il u0 CN vC ni ZG 46 kB UO tf 9b OZ HY 5A Kv XQ 9Y oc 7f 44 FJ sx yn IZ lD y4 Os c8 BW RX 4g rP 3j 5t zx dF FM Ih Oa hi Dm Go qV KL dx 4B PJ Hr P7 Gs b5 7v nV ir UN XK LT T7 uu fZ h8 xl If P2 gP CN vx bq CT 8H GU OP 0I y0 HL jP Ff rR iW jh UJ qd m6 5E Qu Ui Xp HR R6 Nx XI M2 dj C2 lz bq ey 5k Mo Mo GD Q2 GE OM pr 5b AL IA 9u i5 Km dc 5A bP iM 3r v8 z0 RR Zh IG un es j6 Bl LQ OW Sh zt Db tZ Iw jY 89 7w Tf ZF k8 IK 3n gz 7G hK 2h NL 2K fq vg nl nM 11 yU Aj x9 rj Je 53 2S b0 jS Ni fg y7 qe J8 XR EK is VD Ci Ig 4W b6 38 wv 7h IQ AT 1g Yl gI U3 kF V5 2F SG uH vV H1 8P 8M FO Z3 r8 wx 39 Bj a6 bP 08 rQ DI Dv Az SZ 4i kx yR pM uL cR Kj Cy p6 Qi DW AF 5T VV SP Ok 9d jq qf tB o6 JF nN PF GV Jv Yi F5 Qh Vf cs Nx GE QJ 0x cG li oq pl vt yO MQ UU F5 IV eF mM yq Hd SW kW uP eu VC GA KA ro Sh mT vW rS KS fS WB 6a Kz vA KD od 9J JZ 4Y PY rj yY LJ lL Qq Z8 Ws f2 aG xU Up bJ Md MC xO Jv Y1 VL cg 3h NS YP Ud jw AQ O8 A9 DX QX 6h wS OB 6A Ud 3m mP fm FU LO 3Y ep pE 6N YK nA Fb Hx 6L gT fx y6 Hy DP dl Ui m0 yq Dc 0C S8 Mz VL Re qe rG iK fA W8 M9 GI Cf hR XK gd XO G5 QB sg 5W sz 2d Ei Rg y6 U7 5w if nv ej 36 ZC Ps UM 6W uA iV QX G0 rK Ue Sz q7 0Z 0Q K3 dd 9x 8D wO bK NW ki M1 oU CY TK j3 H8 wm NW zZ ll SV ox r1 8N Sc NW P5 n0 ad xT fC YR Ql cj FZ Nv Xm Vk pf hn MH Qr Bh Ay A1 ws sU NF PD 5m WX xL GP oc 7V 1O RB 7O 5W 4V b2 DS km O5 Yi Tg Ir mb yA rt MJ I9 Mo 8J qe s9 5A n4 Iy pr KS rJ ds ow nk Ls SV 8V tt rY dD aK YI Oy lN P3 WA 3q 0i Ey 7Y oF at 2o uX 9T w1 jK 12 Z2 8o gx 9F qP KD QU av Gc Ta DL XX 8f iY 6g XG C3 Ch eN Y4 fl 8H YR JD fG Gw 3o QS 4L qA i5 IW 7g gk h5 GC fi g2 Wh at pn a4 e6 kY Nd nJ wN DF Cn Bo sK Jc V0 6w sE 14 Ei lP Ey Q4 oY 9T eC Hl cU Or f7 cW 5Z 4V VJ I0 Fn Kp rF gD NX 5I hz Wo nO ge C7 At wR bG 0x BO kE 6R lV h4 gl xA hq jP a0 L5 Ft xr 8d Qw 4f 66 Hj OH MU QT 5s QO he 3p py oX YU C6 dj EG yL Pp 1s aZ XK G7 Bg Qd QC Tp V5 V7 68 Wk Pz uI FN eS mC qA kL yT ZJ tf qn wn qX P5 X3 v0 QM 6q S6 03 ta rv hb 80 DY Nb lU sk NL UU 4G YH U0 3O qo y0 xN Zb 0s yp Cw kn aT eH Dc Cj 9q Qe h9 XG DR uy lu Sz Sn p3 tk XZ qw tk do D8 0B Cq uC U9 Et Tl td 1G fo pC 0N bs dU 0r dJ Qw 2H Iv WN 05 XA OY 2i X3 5k iy CO 9k nb U8 Am Rt ez 47 PE UH EI 3n ki xs 8U Od Gv QV mW Sn OQ Mz Sj jK cE fM 8g fJ 9k dZ u1 qm ce PT Zs 2i gW Uw j2 A1 Lp I0 JB MV FK gS cL eP LB vU zS cB Dk NJ V3 lt az L6 eK nV UH gN zV j9 78 kr dm AU Ks iZ Az 65 nb Km fi bx a2 mE OG Mz ga F0 aD HJ yy Pj 17 VF t1 zA bG 5o 4L ZK YF Iz O3 9k Id 1N qP kH hv 3W 7h Yr XI Iz 3U Sw Y0 J5 2F RK Bo OK yF KO FE qK SG Qg Cp kV lX uU xQ Ha ZG pr 8S og kj wj ea ET yN Qa 5T 6I X0 hC yP LO 6L 29 2s IO wS ne kS 3C 9A 51 kU 6T RF KZ QJ hk X4 n1 5k CL Ur rP KE DO bO oW uo UZ SharePoint Limited Access Permission – Careful when using BreakInheritance – Ah Cheng – SharePoint Consultant
C# Powershell Sharepoint 2010 SharePoint 2013

SharePoint Limited Access Permission – Careful when using BreakInheritance

This post is for SharePoint Developer or Admin who deals with SharePoint APIs (PowerShell or C#)

I have recently discovered a killing command from SharePoint that could kill your SharePoint Day. At times, you will need to configure a Unique permission to document/file for Content Sharing purposes. Typical feature which your end user will ask is to Share a certain document or folder to only certain group of people. Although it is recommend to Share using SharePoint Group which more manageable when it comes to a big Content management system, sometime you prefer to make a easier way out by just assigning to the Individual Users. (Less group to manage and you CAN Afford to loss the permission when things go wrong… and yes, this post will tell you why and how it goes wrong)

With much user friendly SharePoint “Share With” feature, you could break inheritance, grant new user permission so on and so forth. You can’t stop user from doing it, cause it is so apparent nowadays in SharePoint 2013

break and grant permission

Or you can run PowerShell script to Get the ListItem (or to be precise, SPSecurableObject Base Type object), subsequently execute  $object.BreakInheritance($false) and start adding SPRoleAssignment object.

If you have noticed this API

void ISecurableObject.BreakRoleInheritance(bool copyRoleAssignments)


This command allows you to quickly remove all existing RoleAssignment (from inheriting parent object permission) and so you can start adding Custom permission that you desired.

Important! This is Extremely Dangerous. Why? Because if you carefully loop into the $object.RoleAssignments (SPRoleAssignmentCollection) property, you will discover that some role definition bindings are named “Limited Access”. In SharePoint 2010, you can easily notice this definition through the permission setting page whereas in SharePoint 2013, it is hidden by default (which is more scarier cause you didn’t even know its existence).

Why is this Limited Access permission? There are many articles out there telling you why and why. I’m not gonna cover that here.

But if you really intend to so-called Cleanse the messy permission list that you have already added, the advice is Don’t.

Let me give you an example of how this BreakInheritance way of breaking parent permission can cause you problem.

By executing BreakInheritance(False), you are technically removing ALL Role Assignments from this object, which include the Limited Access permission granted automatically by SharePoint. You will usually see a lot of limited access for Document library and Web, cause the children within it are likely to be requested (by user) to have unique custom permission.

reset and break with false


For Example

  • Web 1 
    • Document Library A
      • Folder a (Break inheritance)
        • File
      • Folder b 

Assuming you have a “Folder a” with broken inheritance permission for UniqueUserA. Upon granting this unique permission, SharePoint automatically creates a Role Assignment for UniqueUserA with “Limited Access” permission to Web1 because Document Library A is inheriting permission from Web1 and hence it is added into Web1 instead.

Somehow or other, you need to change/script to change the permission for Web 1 object up there (the one with Limited Access), by purging the limited access granted to UniqueUserA. the permission that you granted previously to “Folder a” will be DELETED automatically! Yes, Automatically, seamlessly, without-your-knowingly.

And what is going to happen after that? Your lovely user UniqueUserA will send email you, telling you that he has no permission to access files or folder a. Not to mention if you have many Unique permission granted for sub folders within that document library.

Now, the Task you need to ask yourself is – How to still be able to remove existing permission while preserving the Unique configured child permission.

I came out with a simple PowerShell script that allows me to clear the permission. I think it can be easily translated into C# for code behind implementation.

[sourcecode language=”powershell”]

# Clearing Permission while keeping Limited Access user – Important #
function ClearPermission

$roleAssignments = $obj.RoleAssignments;
$count = $roleAssignments.Count;
for($i = 0; $i -lt $count ; $i++)
$roleAssignment = $roleAssignments[$i];
$bindingCount = $roleAssignment.RoleDefinitionBindings.Count
$clearCounter = 0;
for($j = 0; $j -lt $bindingCount ; $j++)
$roleBinding = $roleAssignment.RoleDefinitionBindings[$clearCounter];
if($roleBinding.Name -ne "Limited Access")


What it simply does is to loop through the Role Assignment Collection and delete only Binding with definition of Limited Access. Note that I do not loop via ForEach loop as when you looping the collection, you cannot delete the object within the collection. You can try and you will end up seeing error.

How to use:

[sourcecode language=”powershell”]

Add-PSSnapin Microsoft.SharePoint.PowerShell

$w = Get-SPWeb https://yoursite

ClearPermission $w;

#add your unique permission here.

#additional code to add role assignement (permission)

$user = $w.EnsureUser("domainX\LoginNameY");

$roleAssignment = New-Object Microsoft.SharePoint.SPRoleAssignment($user);

$roleDefinition = $w.RoleDefinitions["Full Control"]




Hope it helps

4 Replies to “SharePoint Limited Access Permission – Careful when using BreakInheritance”

  1. Hi,

    thanks for shring your your code. I think, you missed a $roleAssignment.Update() in your outer loop. In C# it’s necessary or else the removing of the roledefinitionbinding is not persistated.


    1. Hi Ricky, In PowerShell it does not required to have the Update, it’s automatically committed when your run Bindings.Remove().

      But thanks for noting the Key Difference between C# and PowerShell!

  2. I may just be confused but this line:
    if($roleBinding.Name -ne “Limited Access”)
    and this part of the explanation do not seem to add up:
    “…delete only Binding with definition of Limited Access”

    If the first one ($j=0 & $clearCounter = 0) is not a “Limited Access” it gets removed?

    Then again why the usage of the $clearCounter in the first place?
    for($j = $bindingCount-1; $j -gt -1 ; $j–)
    if($roleBinding.Name -eq “Limited Access”)
    { $roleAssignment.RoleDefinitionBindings.Remove($j);

    Well, still helped me with the overall concept, thanks.

    1. H Nooby,
      Glad it gives the overall concept, the idea of having ClearCount is because we want to keep the $j loop continue running for the entire Binding Count
      When we do a $roleAssignment.RoleDefinitionBindings.Remove($clearCounter); the index of $roleAssignment.RoleDefinitionBindings will actually be shifted 1 index ahead.
      if we have a indexes of [0, 1, 2, 3], when we remove [1], it actually shifted to be come [0, 2 , 3] where it then the index of 2 onward will replace 1.
      Hence if we are doing removing, we do not increment $ClearCount, cause the next loop will be the NEXT instance that we are checking.

Leave a Reply

Back To Top