Guest User

Untitled

a guest
Nov 28th, 2017
387
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.73 KB | None | 0 0
  1. #Load SharePoint CSOM Assemblie
  2. Add-Type -Path "C:Program FilesCommon FilesMicrosoft SharedWeb Server Extensions16ISAPIMicrosoft.SharePoint.Client.dll"
  3. Add-Type -Path "C:Program FilesCommon FilesMicrosoft SharedWeb Server Extensions16ISAPIMicrosoft.SharePoint.Client.Runtime.dll"
  4.  
  5. #Defining Variables
  6. $SiteUrl = "https://site.sharepoint.com"
  7. $ListName = "ListTitle"
  8. $Path = "C:UsersUsernameDesktopfilename.csv"
  9. $UserName = "username@email.com"
  10. $Password = Get-Content "C:UsersUsernameDesktoppassword.txt" | ConvertTo-SecureString -Force
  11.  
  12. #Automated Login Credentials
  13. $Context = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
  14. $credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($UserName, $password)
  15. $Context.Credentials = $credentials
  16.  
  17. #Retrive the List
  18. $List = $Context.web.Lists.GetByTitle($ListName)
  19.  
  20. #Get All List Items
  21. $Query = New-Object Microsoft.SharePoint.Client.CamlQuery
  22. $ListItems = $List.GetItems($Query)
  23. $context.Load($ListItems)
  24. $context.ExecuteQuery()
  25.  
  26. # Turn item into a catch array
  27. $ListItemCollection = @()
  28.  
  29. #Fetch each list item value to export to excel
  30. $ListItems | foreach {
  31. $ExportItem = New-Object PSObject
  32. $ExportItem | Add-Member -MemberType NoteProperty -name "Title" -value $_["Title"]
  33.  
  34. #Add the object with above properties to the Array
  35. $ListItemCollection += $ExportItem
  36. }
  37. #Export the result Array to CSV file
  38. $ListItemCollection | Export-CSV $Path -NoTypeInformation
  39.  
  40. Write-host "Deed has been done!"
  41.  
  42. $ListItems | % {
  43. $propertiesValues = New-Object PSObject;
  44. $currentItem = $_;
  45. $_.FieldValues.Keys | ? {$_ -ne "MetaInfo"} | % {
  46. Add-Member -InputObject $propertiesValues -MemberType NoteProperty -Name $_ -Value $currentItem[$_]
  47. };
  48. $propertiesValues}
Add Comment
Please, Sign In to add comment