
those example which you provided uses server object model PowerShell cmdlets - they work only with Sharepoint on-prem (not with Sharepoint online) and only when this PowerShell runs on the server which is part of Sharepoint farm.
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Hi.
I am trying to export the SharePoint list data to CSV by following this link :
https://www.sharepointdiary.com/2013/04/export-sharepoint-list-items-to-csv-using-powershell.html
I am following the last example given. i am trying the code as :
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
$SiteUrl="sharepoint site"
$ListName="list name"
$OutPutFile = "C:\path\ListData.csv"
If (Test-Path $OutPutFile) { Remove-Item $OutPutFile }
$Web = Get-SPWeb $SiteUrl
$List = $Web.Lists[$ListName]
Write-host "Total Number of Items Found:"$List.Itemcount
I am getting error while running in powershell as Get-SPWeb : The term 'Get-SPWeb' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was
included, verify that the path is correct and try again.
How to fix this ?
Thanks
Update 1: I have tried this :
PS C:\WINDOWS\system32> Install-Module -Name Microsoft.Online.SharePoint.PowerShell
PS C:\WINDOWS\system32>
Add-PSSnapin Microsoft.SharePoint.PowerShell
Add-PSSnapin : The Windows PowerShell snap-in 'Microsoft.SharePoint.PowerShell' is not installed on this computer.
At line:2 char:1
I do not see a folder named Microsoft.SharePoint.Powershell in the C:\Windows\Microsoft.NET\assembly\GAC_MSIL path.
Can powershell be run from client machine, where sharepoint is not installed ?
those example which you provided uses server object model PowerShell cmdlets - they work only with Sharepoint on-prem (not with Sharepoint online) and only when this PowerShell runs on the server which is part of Sharepoint farm.
The code you provided is for SharePoint on-prem and not for SharePoint Online. It is recommended that you can run the following PowerShell script as an admin:
Export SharePoint Online List Items to CSV using PowerShell
#Config Parameter
$SiteURL = "https://domain.sharepoint.com/sites/sitename"
$ListName = "listname"
#InternalName of the selected fields
$SelectedFields = @("ID","Title","Choice1","Person1","Date1")
$CSVPath = "C:\Temp\ListData.csv"
$ListDataCollection= @()
#Connect to PnP Online
Connect-PnPOnline -Url $SiteURL -Credentials (Get-Credential)
$Counter = 0
#PageSize:The number of items to retrieve per page request
$ListItems = Get-PnPListItem -List $ListName -Fields $SelectedFields -PageSize 2000
#Get all items from list
$ListItems | ForEach-Object {
$ListItem = Get-PnPProperty -ClientObject $_ -Property FieldValuesAsText
$ListRow = New-Object PSObject
$Counter++
ForEach($Field in $SelectedFields)
{
$ListRow | Add-Member -MemberType NoteProperty $Field $ListItem[$Field]
}
Write-Progress -PercentComplete ($Counter / $($ListItems.Count) * 100) -Activity "Exporting List Items..." -Status "Exporting Item $Counter of $($ListItems.Count)"
$ListDataCollection += $ListRow
}
#Export the result Array to CSV file
$ListDataCollection | Export-CSV $CSVPath -NoTypeInformation
Reference:
Thanks,
Echo Du
=========================================
If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.