Need Help with Array

Welcome Forums General PowerShell Q&A Need Help with Array

This topic contains 3 replies, has 3 voices, and was last updated by

2 years, 8 months ago.

  • Author
  • #46891

    Points: 4
    Rank: Member

    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

    $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

    Points: 1
    Rank: Member

    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)

    • #46978

      Points: 4
      Rank: Member

      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 🙂


  • #46945

    Points: 0
    Rank: Member
    Group-BrokerMachine #...# | Measure-Object -Property Count -Sum | Select-Object -ExpandProperty Sum

    Measure-Object can add the values of a property.

The topic ‘Need Help with Array’ is closed to new replies.

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort