Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $mQueryRowLimit = 200
- #Specify tenant admin and site URL
- $User = "t@t.com.mt"
- $SiteURL = "https://t.sharepoint.com"
- $ListTitle = "Demo"
- #Add references to SharePoint client assemblies and authenticate to Office 365 site – required for CSOM
- Add-Type -Path "C:SPServerDLLsMicrosoft.SharePoint.Client.dll"
- Add-Type -Path "C:SPServerDLLsMicrosoft.SharePoint.Client.Runtime.dll"
- $Password = Read-Host -Prompt "Please enter your password" -AsSecureString
- $Creds = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($User,$Password)
- #Bind to site collection
- $Context = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
- $Creds = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($User,$Password)
- $Context.Credentials = $Creds
- getAllListItems -_ctx $Context -_listName $ListTitle -_rowLimit $mQueryRowLimit
- $Context.Dispose()
- function getAllListItems($_ctx, $_listName, $_rowLimit)
- {
- # Load the up list
- $lookupList = $_ctx.Web.Lists.GetByTitle($_listName)
- $_ctx.Load($lookupList)
- # Prepare the query
- $query = New-Object Microsoft.SharePoint.Client.CamlQuery
- $query.ViewXml = "<View>
- <RowLimit>$_rowLimit</RowLimit>
- </View>"
- # An array to hold all of the ListItems
- $items = @()
- # Get Items from the List until we reach the end
- do
- {
- $listItems = $lookupList.getItems($query)
- $_ctx.Load($listItems)
- $_ctx.ExecuteQuery()
- $query.ListItemCollectionPosition = $listItems.ListItemCollectionPosition
- foreach($item in $listItems)
- {
- Try
- {
- # Add each item
- WriteHost $item['Company']
- $items += $item
- }
- Catch [System.Exception]
- {
- # This shouldn't happen, but just in case
- Write-Host $_.Exception.Message
- }
- }
- }
- While($query.ListItemCollectionPosition -ne $null)
- #return $items
- $_ctx.Dispose()
- }
- WriteHost $item['Company']
- WriteHost $item['City']
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement