-2

I have a SharePoint list called "ListA" which has the following columns Id, Name, Company and Address

The list contains many records and I want to get all items in the list based on a Company name "C" and write the Item name. How can I iterate through the list using SharePoint Powershell script?

OseeAliz
  • 69
  • 3
  • 10
  • 1
    Possible duplicate of [How to get items from a sharepoint online list using PowerShell](http://stackoverflow.com/questions/32699338/) and [Client-side SharePoint PowerShell - Get list items](http://http://stackoverflow.com/questions/37788615) and [Update all items in a list using PowerShell](http://http://stackoverflow.com/questions/9946801) and [Get a collection of items in document library/list](http://http://stackoverflow.com/questions/31843222) – TessellatingHeckler Sep 09 '16 at 07:38

1 Answers1

0

Provided you have an on-premise SharePoint farm, here is a brief snippet that should get you what you are looking for:

# Define the URL of the site collection you will be querying
$siteURL = "http://yourfarm.domain.com/"
# Define the Title of the web that hosts your list
$webTitle = "TheWebTheListIsOn"
# Define the Title of the List that you will be querying
$listTitle = "ListA"

# Create a unique file name for the csv export
$date = Get-Date -UFormat "%Y%m%d"
$csvFilePath = "$($webTitle.Replace(' ',''))_$($listName.Replace(' ',''))_$($date).csv"

# Query the list based on a criteria and export to csv 
$items = Get-SPSite -Identity $siteURL `
    | select -ExpandProperty AllWebs `
    | where { $_.Title -eq $webTitle } `
    | select -ExpandProperty Lists `
    | where { $_.Title -eq $listTitle } `
    | select -ExpandProperty Items `
    | where { $_['Company'] -like "C*" } `
    | select Id, Name, Company, Address `
    | Export-Csv -NoTypeInformation -Path $csvFilePath