Dismiss Notice

Register now to be one of the first members of this SharePoint Community! Click here it just takes seconds!

Dismiss Notice
Welcome Guest from Country Flag

Powershell script to group Sharepoint list items and sum a quantity field

Discussion in 'Official Microsoft News' started by Sean Burke, Dec 16, 2015.

Thread Status:
Not open for further replies.
  1. Sean Burke

    Sean Burke Guest

    Blog Posts:
    0
    0
    0
    0
    Hi All,

    I've been trying to write a powershell script to grab data from a sharepoint list to:

    • Group the items by the Title field
    • Sum the Quantity field of the like items

    For example, if the list has:

    Title Quantity
    Coke 4
    Sprite 3
    Sprite 2
    Coke 1
    Coke 8

    Then the Powershell script would output:

    Title Quantity
    Coke 13
    Sprite 5

    Here's my script:

    $web = Get-SPWeb "https://intranet.oursite.com/"
    $list =$web.GetList("/sites/test/Lists/Order")
    $view = $list.Views["ScriptTest"]
    $exportlist = $null
    $exportlist = @()
    $items = $list.GetItems($view) | Group-Object $_['Title']
    $items | select-object -property @{Name='Title';expression={$_['Title']}}, @{Name='Quantity';expression={($_Group | Measure-Object -Property $_['Quantity'] -Sum).Sum }}

    The issue I'm having is that it doesn't recognize the Quantity field so the output is empty.

    Thanks in advance.

    Continue reading...
     
Thread Status:
Not open for further replies.

Share This Page

LiveZilla Live Chat Software