lundi 2 février 2015

SharePoint Online Iterating through Document Libraries CSOM



I am trying to iterate though a document library and set each document/items within 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 = "http://ift.tt/1yJKrtK"
$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)


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


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.








0 commentaires:

Enregistrer un commentaire