Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Load SharePoint CSOM Assemblie
- Add-Type -Path "C:Program FilesCommon FilesMicrosoft SharedWeb Server Extensions16ISAPIMicrosoft.SharePoint.Client.dll"
- Add-Type -Path "C:Program FilesCommon FilesMicrosoft SharedWeb Server Extensions16ISAPIMicrosoft.SharePoint.Client.Runtime.dll"
- #Defining Variables
- $SiteUrl = "https://site.sharepoint.com"
- $ListName = "ListTitle"
- $Path = "C:UsersUsernameDesktopfilename.csv"
- $UserName = "username@email.com"
- $Password = Get-Content "C:UsersUsernameDesktoppassword.txt" | ConvertTo-SecureString -Force
- #Automated Login Credentials
- $Context = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
- $credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($UserName, $password)
- $Context.Credentials = $credentials
- #Retrive the List
- $List = $Context.web.Lists.GetByTitle($ListName)
- #Get All List Items
- $Query = New-Object Microsoft.SharePoint.Client.CamlQuery
- $ListItems = $List.GetItems($Query)
- $context.Load($ListItems)
- $context.ExecuteQuery()
- # Turn item into a catch array
- $ListItemCollection = @()
- #Fetch each list item value to export to excel
- $ListItems | foreach {
- $ExportItem = New-Object PSObject
- $ExportItem | Add-Member -MemberType NoteProperty -name "Title" -value $_["Title"]
- #Add the object with above properties to the Array
- $ListItemCollection += $ExportItem
- }
- #Export the result Array to CSV file
- $ListItemCollection | Export-CSV $Path -NoTypeInformation
- Write-host "Deed has been done!"
- $ListItems | % {
- $propertiesValues = New-Object PSObject;
- $currentItem = $_;
- $_.FieldValues.Keys | ? {$_ -ne "MetaInfo"} | % {
- Add-Member -InputObject $propertiesValues -MemberType NoteProperty -Name $_ -Value $currentItem[$_]
- };
- $propertiesValues}
Add Comment
Please, Sign In to add comment