Break inheritance for all SharePoint Online lists in a site

Powershell script to break inherited permissions for all SharePoint Online lists in a site collection.  Before you run it, you have to modify one last line of the script!

 
 
 
 
 
5 Star
(1)
1,053 times
Add to favorites
Office 365
1/17/2015
E-mail Twitter del.icio.us Digg Facebook
Sign in to ask a question


  • The collection has not been initialized. It has not been requested or the request has not been executed. It may need to be explicitly requested.
    3 Posts | Last post December 20, 2018
    • This script doesn't work for me.  I have tried to run it and also step through to debug it.  
      
      The problem appears to be related to this
        $ctx=New-Object Microsoft.SharePoint.Client.ClientContext($Url)
        $ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Username, $azurepassword)
        $ctx.Load($ctx.Web.Lists)
        $ctx.Load($ctx.Web)
        $ctx.Load($ctx.Web.Webs)
        $ctx.ExecuteQuery()
      
      When I run "$ctx.Web" I get the error above I have done some additional internet searches and found the following links
      http://sharepoint.stackexchange.com/questions/44100/powershell-and-the-client-object-model-the-collection-has-not-been-initialized
      http://sharepoint.stackexchange.com/questions/44100/powershell-and-the-client-object-model-the-collection-has-not-been-initialized
      
      In both cases it appears that you need to explicitly call but I am not really sure what that means.  any help would be appreciated.
      
      Thank you
      Chris
    • Have you inserted your data at the end of the script? What url are you using, can you post it here?
      Which line exactly gives you the error?
    • On re-reading your question - I know you probably won't come back here, Clearwaterms, but maybe it will help the others.
      
      You cannot output $ctx.Web, because not all of its properties have been initialized. One of these properties is a collection (e.g. Alerts, RssFeeds) and it is throwing you this error.
      If you want to display a particular property of the web object, you can do it in the following way:
      Write-host $ctx.Web.Created
      
      For some of the properties, you may need to load them first, e.g.
      $fields=$ctx.Web.Fields
      $ctx.Load($fields)
      $ctx.ExecuteQuery()
      
      Write-output $fields
  • How can I limit this to one list?
    2 Posts | Last post December 20, 2018
    • Thank you so much for your scripts, I use them a lot! I really need to break inheritance with one of my (LARGE) lists, but can't figure it out. Is there any way to specify 1 list, not all?
    • Hi Brock Albitz,
      
      I created here a version that breaks inheritance only for one list. Have a look and let me know if this is what you are looking for:
      https://gallery.technet.microsoft.com/office/Break-role-inheritance-for-6c6534b8
  • MissingMethodException
    1 Posts | Last post February 04, 2016
    • PS C:\Users\xxxxxx\Downloads> C:\Users\xxxxxx\Downloads\SetUniquePermissions for all lists.ps1
      Exception calling "ExecuteQuery" with "0" argument(s): "Method not found: 'Boolean System.Net.WebResponse.get_SupportsHeaders()'."
      At C:\Users\xxxxxx\Downloads\SetUniquePermissions for all lists.ps1:23 char:3
      +   $ctx.ExecuteQuery()
      +   ~~~~~~~~~~~~~~~~~~~
          + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
          + FullyQualifiedErrorId : MissingMethodException
       
      
      https://xxxxxx.sharepoint.com
      The type initializer for 'Microsoft.SharePoint.Client.Resources' threw an exception.
      At C:\Users\xxxxxx\Downloads\SetUniquePermissions for all lists.ps1:26 char:12
      +   foreach( $ll in $ctx.Web.Lists)
      +            ~~~
          + CategoryInfo          : OperationStopped: (:) [], TypeInitializationException
          + FullyQualifiedErrorId : System.TypeInitializationException