none
How to Iterate trough sharepoint lists based on the column value using PowerShell? RRS feed

  • Question

  • Hi everybody!

    I have a list which has like 10 different columns. This list is constantly updated. There are two columns on which I have to filter out my results.

    One of the column is "new or existing" (Value: New or existing)  and the second is: "Status" with the values (completed, in migration, etc, etc). I want to filter out the list based on the column values of  "New" and "Completed" using a Powershell Script.

    Can anyone please help me out. Is there a way I can export the result into a csv file.

    Thanks

    Tuesday, February 28, 2017 5:37 AM

All replies

  • Hi,

    The following PowerShell script for your reference:

    #Get the Web
    $web = Get-SPWeb -identity "http://sp13/sites/test1"
    
    #Get the Target List
    $list = $web.Lists["CustomList6"]
    
    #Array to Hold Result - PSObjects
    $ListItemCollection = @()
    
    #Get All List items where new or existing is "New" and Status is "Completed"
    $list.Items |  Where-Object { $_["new or existing"] -eq "New" -and $_["Status"] -eq "Completed"} | foreach {
    
    	$ExportItem = New-Object PSObject 
    	$ExportItem | Add-Member -MemberType NoteProperty -name "Title" -value $_["Title"]
    	$ExportItem | Add-Member -MemberType NoteProperty -Name "new or existing" -value $_["new or existing"]
    	$ExportItem | Add-Member -MemberType NoteProperty -name "Status" -value $_["Status"]
    
    	#Add the object with property to an Array
    	$ListItemCollection += $ExportItem
    
    }
    
    #Export the result Array to CSV file
    $ListItemCollection | Export-CSV "c:\ListData.csv" -NoTypeInformation                       
    
    #Dispose the web Object
    $web.Dispose()

    Best Regards,

    Dennis


    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com


    Wednesday, March 1, 2017 7:30 AM
    Moderator
  • Hi,

    Any update?

    If the reply help you, please mark the reply as answer, it will make others who stuck with the similar issue easier to search for valid solutions in this forum.

    Best regards,
    Dennis


    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com

    Thursday, March 9, 2017 10:30 AM
    Moderator