Quantcast
Viewing all articles
Browse latest Browse all 10096

SharePoint Online Iterating through Document Libraries CSOM

Hi,

I am trying to iterate though a document library and set each document/items whithin to inherit permissions (at the moment each doc/item is using uniquer permissions).

I am able to get the specific document library that I am interesting in, however I cannot at the moment iterate though each of the items/documents within it, but here is what I have so far:

Add-Type -Path "Libraries\Microsoft.SharePoint.Client.dll"
Add-Type -Path "Libraries\Microsoft.SharePoint.Client.Runtime.dll"
Add-Type -Path "Libraries\Microsoft.SharePoint.Linq.dll"
Add-Type -Path "Libraries\Microsoft.SharePoint.dll"

$webUrl = "https://test.sharepoint.com/sites/testsite"
$username = "####"
$password = "####"
$securePass = ConvertTo-SecureString $password -AsPlainText -Force
$listname = "TestDoc";

$ctx = New-Object Microsoft.SharePoint.Client.ClientContext($webUrl)
$ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($username, $securePass)

#variables
$web = $ctx.Web
$lists = $web.Lists
$ctx.Load($lists)
$ctx.Load($web)
$ctx.ExecuteQuery()

#print web URL
write-host `n "Web Url:" `n $web.Url

foreach ($list in $lists)
{

    if ($list.Title -eq "TestDoc")
    {
        #print list name if found
        write-host `n "Found the list:" `n $list.Title `n


            #attempting to iterate through items in the document library
            foreach ($item2 in $list.Items)
            {
                #list the items/documents  in the document library
                write-host $item2.Title
            }


    }
}

It is the foreach loop I am having trouble at the moment as I am not sure how to loop though each of the items/documents in the document library.

Any suggestions on the approach I should take would be much appreciated.


Viewing all articles
Browse latest Browse all 10096

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>