Advertisement
Guest User

Untitled

a guest
Aug 18th, 2016
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.02 KB | None | 0 0
  1. $mQueryRowLimit = 200
  2. #Specify tenant admin and site URL
  3. $User = "t@t.com.mt"
  4. $SiteURL = "https://t.sharepoint.com"
  5. $ListTitle = "Demo"
  6.  
  7. #Add references to SharePoint client assemblies and authenticate to Office 365 site – required for CSOM
  8. Add-Type -Path "C:SPServerDLLsMicrosoft.SharePoint.Client.dll"
  9. Add-Type -Path "C:SPServerDLLsMicrosoft.SharePoint.Client.Runtime.dll"
  10. $Password = Read-Host -Prompt "Please enter your password" -AsSecureString
  11. $Creds = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($User,$Password)
  12.  
  13. #Bind to site collection
  14. $Context = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
  15. $Creds = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($User,$Password)
  16. $Context.Credentials = $Creds
  17.  
  18. getAllListItems -_ctx $Context -_listName $ListTitle -_rowLimit $mQueryRowLimit
  19. $Context.Dispose()
  20.  
  21. function getAllListItems($_ctx, $_listName, $_rowLimit)
  22. {
  23. # Load the up list
  24. $lookupList = $_ctx.Web.Lists.GetByTitle($_listName)
  25. $_ctx.Load($lookupList)
  26.  
  27. # Prepare the query
  28. $query = New-Object Microsoft.SharePoint.Client.CamlQuery
  29. $query.ViewXml = "<View>
  30. <RowLimit>$_rowLimit</RowLimit>
  31. </View>"
  32.  
  33. # An array to hold all of the ListItems
  34. $items = @()
  35.  
  36. # Get Items from the List until we reach the end
  37. do
  38. {
  39. $listItems = $lookupList.getItems($query)
  40. $_ctx.Load($listItems)
  41. $_ctx.ExecuteQuery()
  42. $query.ListItemCollectionPosition = $listItems.ListItemCollectionPosition
  43.  
  44. foreach($item in $listItems)
  45. {
  46. Try
  47. {
  48. # Add each item
  49. WriteHost $item['Company']
  50. $items += $item
  51. }
  52. Catch [System.Exception]
  53. {
  54. # This shouldn't happen, but just in case
  55. Write-Host $_.Exception.Message
  56. }
  57. }
  58. }
  59. While($query.ListItemCollectionPosition -ne $null)
  60.  
  61. #return $items
  62. $_ctx.Dispose()
  63. }
  64.  
  65. WriteHost $item['Company']
  66.  
  67. WriteHost $item['City']
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement