Need Help with Array

Dear Community
I need your help , I am trying to total count property values in an array . I come up with the below code but I am sure there could be better way to do this :slight_smile: . Can you take a look and suggest . Thanks in advance. Thanks.

$Query = Group-BrokerMachine -Property Registrationstate -AdminAddress $Adminserver
$TotalDesktops = $Query[0].count + $Query[1].count + $Query[2].count + $Query[3].count

$query | gm
Name MemberType Definition

Equals Method bool Equals(System.Object obj)
GetHashCode Method int GetHashCode()
GetType Method type GetType()
ToString Method string ToString()
Count Property int Count {get;set;}
Name Property string Name {get;set;}

Dont use it myself, but i found:

Groups and counts machines with the same value for a specified property.

C:\PS> Group-BrokerMachine -Property SummaryState
Count Name

43 Available
17 InUse
3 Disconnected

So whats in $query and what is the output you want?
(Group-BrokerMachine -Property Registrationstate -AdminAddress $Adminserver)

Group-BrokerMachine #...# | Measure-Object -Property Count -Sum | Select-Object -ExpandProperty Sum

Measure-Object can add the values of a property.

Hi Chris
I want to sum up the count property value , sorry i was not quite clear in my post but thanks for helping :).

I used craig method and it worked. Thanks Craig :slight_smile: