Guest User

Untitled

a guest
Feb 14th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.23 KB | None | 0 0
  1. Function Get-ListItems([Microsoft.SharePoint.Client.ClientContext]$Context, [String]$ListTitle) {
  2. $list = $Context.Web.Lists.GetByTitle($ListTitle)
  3. $items = $list.GetItems([Microsoft.SharePoint.Client.CamlQuery]::CreateAllItemsQuery())
  4. $Context.Load($items)
  5. $Context.ExecuteQuery()
  6. return $items
  7. }
  8.  
  9. #set environment
  10. $targetsite = "https://sites/testsite"
  11. $targetlist = "testlist"
  12.  
  13. $adminUsername = "admin@account"
  14. $secureAdminPassword = Read-Host -AsSecureString "please enter password"
  15.  
  16. #ask the user to log in
  17. $usercredentials = Get-Credential
  18. #creating sharepiont credentials object
  19.  
  20. #$sharepointcred = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($usercredentials.UserName, $usercredentials.Password)
  21. $sharepointcred = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($adminUsername, $secureAdminPassword)
  22. #tried both
  23.  
  24.  
  25. #create context
  26. $Context = New-Object Microsoft.SharePoint.Client.ClientContext($targetsite)
  27. #assign sharepoint credentials to context
  28. $Context.Credentials = $sharepointcred
  29. #read list
  30. $list = Get-ListItems -Context $Context -ListTitle $targetlist
  31.  
  32. $items = Get-ListItems -Context $context -ListTitle $targetlist
  33. foreach($item in $items)
  34. {
  35. Write-Host $item.Title
  36. }
Add Comment
Please, Sign In to add comment