Need Help with Array

This topic contains 3 replies, has 3 voices, and was last updated by Profile photo of Suresh krishnan Suresh krishnan 4 months, 3 weeks ago.

  • Author
    Posts
  • #46891
    Profile photo of Suresh krishnan
    Suresh krishnan
    Participant

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

  • #46917
    Profile photo of Chris Bakker
    Chris Bakker
    Participant

    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)

    • #46978
      Profile photo of Suresh krishnan
      Suresh krishnan
      Participant

      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

  • #46945
    Profile photo of Craig Duff
    Craig Duff
    Participant
    Group-BrokerMachine #...# | Measure-Object -Property Count -Sum | Select-Object -ExpandProperty Sum

    Measure-Object can add the values of a property.

You must be logged in to reply to this topic.