0

I want to export my SharePoint document library data on daily basis and csv file need to be save as naming convention as Dataname_yyyyMMdd. As per my below script, it need to export data from the sharepoint library into one CSV file as name Data_yyyyMMdd. Then it need to imports the data from Data_yyyyMMdd and adds "header" to the file and then export to new final output CSV as name "DataName_yyyyMMdd".

While running the script i am getting only one file as Data_yyyyMMdd. The data from file was not importing to final csv file and its not generating the final output file DataName_yyyyMMdd. Please correct me if doing wrong in script. Please share me correct script.

Powershell script

$web = get-spweb $siteUrl $caseLib = $web.lists | where {$_.title -eq $listTitle} $query=new-object Microsoft.SharePoint.SPQuery $query.ViewFields = "" $query.RowLimit=5000

do

$ListName1 = "Data" $ExportFolder1 = “C:\Users\” $ExportName1 = Get-Date -f “yyyyMMdd” $ExportPath1 = $ExportFolder1 + $ListName1 + $ExportName1 + “.csv” $ListName = "Dataname_" $ExportFolder = “C:\Users\csv\” $ExportName = Get-Date -f “yyyyMMdd” $ExportPath = $ExportFolder + $ListName + $ExportName + “.csv” { $caseLibItems=$caseLib.GetItems($query) $query.ListItemCollectionPosition=$caseLibItems.ListItemCollectionPosition $listItemsTotal = $caseLibItems.Count $x = 0 for($x=0;$x -lt $listItemsTotal; $x++) { $Description = $caseLibItems[$x]["DocumentSetDescription"] $str = "" if('$Description' -ne $null) { $Description = $Description -replace "n"," " -replace "r"," " $str = $caseLibItems[$x]["LinkFilename"].ToString() + '}' + $Description } else { $str = $caseLibItems[$x]["LinkFilename"].ToString() }

Write-Output $str | Out-File $ExportPath1 -Append
}

} while ($query.ListItemCollectionPosition -ne $null)

Import-csv $ExportPath1 -delimiter "}" -Header "Number", "Description" | export-csv $ExportPath -NoTypeInformation

Write-Host "Exiting"

0

Export SharePoint list data to CSV

Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

Get the Web

$web = Get-SPWeb -identity "sitename"

Get the Target List

$list = $web.Lists["Monthly Schedule Log"]

Array to Hold Result - PSObjects

$ListItemCollection = @()

#Get All List items where Status is "In Progress" $list.Items | Where-Object { $["Status"] -eq "In Progress"} | foreach { $ExportItem = New-Object PSObject $ExportItem | Add-Member -MemberType NoteProperty -name "Title" -value $["Title"] $ExportItem | Add-Member -MemberType NoteProperty -Name "Department" -value $["Department"] $ExportItem | Add-Member -MemberType NoteProperty -name "Status" -value $["Status"] $ExportItem | Add-Member -MemberType NoteProperty -name "Priority" -value $_["Priority"]

#Add the object with property to an Array $ListItemCollection += $ExportItem } #Export the result Array to CSV file $ListItemCollection | Export-CSV "c:\List.txt" -NoTypeInformation

Dispose the web Object

$web.Dispose()

All fields Export using PowerShell

Variables

$SiteUrl="site" $OutPutFile = "location"

Get Web and User Information List

$web = Get-SPWeb $SiteUrl $UserInfoList = $Web.SiteUserInfoList Write-host "Total Number of Items Found:"$UserInfoList.Itemcount

Array to Hold Result - PSObjects

$ListItemCollection = @()

#Get All List items where Status is "In Progress" $UserInfoList.Items | foreach { write-host "Processing Item ID:"$_["ID"]

$ExportItem = New-Object PSObject #Get Each field foreach($Field in $.Fields) { $ExportItem | Add-Member -MemberType NoteProperty -name $Field.InternalName -value $[$Field.InternalName]
} #Add the object with property to an Array $ListItemCollection += $ExportItem

}

Export the result Array to CSV file

$ListItemCollection | Export-CSV $OutPutFile -NoTypeInformation Write-host "User Information List Exported to $($OutputFile) for site $($SiteURL)"

$web.Dispose()

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.