Author Posts

July 14, 2016 at 2:46 am

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 🙂 . 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
$TotalDesktops

$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;}

July 14, 2016 at 8:34 am

Dont use it myself, but i found:

Group-BrokerMachine
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)

July 14, 2016 at 12:23 pm

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

Measure-Object can add the values of a property.

July 14, 2016 at 2:21 pm

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 🙂

Cheers