Powershell : Retrieve sharepoint list data

venkatesh padmanabhan 181 Reputation points

I am trying to export the SharePoint list data to CSV by following this link :


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"

Delete the Output File if exists

If (Test-Path $OutPutFile) { Remove-Item $OutPutFile }

Get Web and List Objects

$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 ?

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

  • Add-PSSnapin Microsoft.SharePoint.PowerShell
  • ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  • CategoryInfo : InvalidArgument: (Microsoft.SharePoint.PowerShell:String) [Add-PSSnapin], PSArgumentException
  • FullyQualifiedErrorId : AddPSSnapInRead,Microsoft.PowerShell.Commands.AddPSSnapinCommand

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 ?

SharePoint Server Development
SharePoint Server Development
SharePoint Server: A family of Microsoft on-premises document management and storage systems.Development: The process of researching, productizing, and refining new or existing technologies.
1,542 questions
Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,180 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. sadomovalex 3,621 Reputation points

    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.

    1 person found this answer helpful.
    0 comments No comments

  2. Echo Du_MSFT 17,056 Reputation points

    Hi @venkatesh padmanabhan ,

    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  
            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  





    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.