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 1 year ago.

  • Author
  • #72778

    Jeff Taylor

    I ran this:

    Get-ADObject -Filter {name -like 'Unique_Bob'} -Properties * -Server | 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?


  • #72779

    Don Jones

    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

      Thanks Don

      Get-ADObject -Filter {name -like 'Unique_Bob'} -Properties * -Server | 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 | gm | Where-Object MemberType -EQ Property | (measure).count

      and went down in flames.

  • #72785

    Don Jones

    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

      hmm I see this:

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

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

  • #72790

    Don Jones

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

    Where, then Measure, then Select.

    • #72887

      Jeff Taylor

      ah, Check... Thank ya kindly.

You must be logged in to reply to this topic.