How do I count the # of properties returned from a Get-?

This topic contains 6 replies, has 2 voices, and was last updated by  Jeff Taylor 2 months ago.

  • Author
    Posts
  • #72778

    Jeff Taylor
    Participant

    I ran this:

    Get-ADObject -Filter {name -like 'Unique_Bob'} -Properties * -Server domain.com | measure

    ...but actually wanted to count the total of all properties returned (not just the number of users named "bob").

    How could I quickly accomplish this?

    thanks

  • #72779

    Don Jones
    Keymaster

    Pipe to Get-Member, and then pipe that output to Where-Object to filter for only those members which are properties, and pipe that to Measure-Object.

    • #72784

      Jeff Taylor
      Participant

      Thanks Don

      Get-ADObject -Filter {name -like 'Unique_Bob'} -Properties * -Server domain.com | gm | Where-Object MemberType -EQ Property | measure

      How do I do that trick where I just get the "count"?

      Tried this:

      Get-ADObject -Filter {name -like 'Unique_Bob'} -Properties * -Server domain.com | gm | Where-Object MemberType -EQ Property | (measure).count

      and went down in flames.

  • #72785

    Don Jones
    Keymaster

    Yeah, that's because you're executing Measure as a single command with no input. That's what parentheses do. You're trying to copy something you've seen in other contexts ;).

    Just add "| Select-Object Count" to the end if you only want to see the Count property.

    • #72788

      Jeff Taylor
      Participant

      hmm I see this:

      ... gm | Where-Object MemberType -EQ Property | Select-Object count
      
      count
      -----
      

      (lots of empty space but no "measured' count of the Property's)

  • #72790

    Don Jones
    Keymaster

    Well, you deleted Measure-Object, dude. That's what generates an object with the Count property.

    Where, then Measure, then Select.

    • #72887

      Jeff Taylor
      Participant

      ah, Check... Thank ya kindly.

You must be logged in to reply to this topic.