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.

(Visited 232 times, 1 visits today)
Add a Comment