Quantcast
Channel: The Official Scripting Guys Forum! forum
Viewing all articles
Browse latest Browse all 15028

Aggregate SP List Items in an array

$
0
0

I have a Sharepoint list that contains items in the following format:

Site         Plan Type          Status          Count

AAA        Manufacturing    Started           1

AAA        Manufacturing    Not Started     2

AAA        Manufacturing    Completed      3

AAA        Office                  Started           2

AAA        Office                  Not Started    1

AAA        Office                  Completed      3

I'm looking retrieve the sum  Status items for a specific Site code, and their values and then create a new custom object which will be added it to an array.   

Below is the Foreach loop to create the new object but how do I aggregate them from 6 entires to just 3 with total sum count?

[array]$Array= @()


Foreach

($iin$RPItems) {

$ID=$i.ID

$Item=$RP.GetItemById($ID)

$obj=New-ObjectPSObject-Property @{

     Site =$i["Site"]

}

if ($i["Status"]-eq"Completed") {

$obj |Add-MemberNoteProperty-NameCompleted-Value$i["Count"]

}

if ($i["Status"]-eq"Started" ) {

$obj |Add-MemberNoteProperty-NameStarted-Value$i["Count"]

}

if ($i["Status"]-eq"Not Started" ) {

$obj |Add-MemberNoteProperty-Name"Not Started"-Value$i["Count"]

}

$Array+=$obj

}

Any advice would be appreciated

Thanks...Joe



Viewing all articles
Browse latest Browse all 15028

Trending Articles