Only get a single instance in an array

This topic contains 3 replies, has 2 voices, and was last updated by  Simon B 3 weeks ago.

  • Author
    Posts
  • #97404

    Dougie Carson
    Participant

    Hi Guys,
    Any help would be appreciated as I have no idea how to tackle this.
    I am pulling storage space information from PRTG using a web API request.
    I end up with an array with the below data.
    1/01/2018 7:00:00 PM – 8:00:00 PM 5497289703424.00
    1/01/2018 8:00:00 PM – 9:00:00 PM 5497289703424.00
    1/01/2018 9:00:00 PM – 10:00:00 PM 5497289703424.00
    1/01/2018 10:00:00 PM – 11:00:00 PM 5497289703424.00
    1/01/2018 11:00:00 PM – 12:00:00 AM 5497289703424.00
    2/01/2018 12:00:00 AM – 1:00:00 AM 5497289703424.00
    2/01/2018 1:00:00 AM – 2:00:00 AM 5497289703424.00
    2/01/2018 2:00:00 AM – 3:00:00 AM 5497289703424.00
    2/01/2018 3:00:00 AM – 4:00:00 AM 5497289703424.00
    2/01/2018 4:00:00 AM – 5:00:00 AM 5497289703424.00
    2/01/2018 5:00:00 AM – 6:00:00 AM 5497289703424.00

    I only want to keep the first line on each day. How could i remove the rest and accomplish this?

    Thanks
    Douglas

  • #97406

    Simon B
    Participant

    you could do something like this

    $myarray = @(
    ("1/01/2018 7:00:00 PM – 8:00:00 PM 5497289703424.00"),
    ("1/01/2018 8:00:00 PM – 9:00:00 PM 5497289703424.00"),
    ("1/01/2018 9:00:00 PM – 10:00:00 PM 5497289703424.00"),
    ("1/01/2018 10:00:00 PM – 11:00:00 PM 5497289703424.00"),
    ("1/01/2018 11:00:00 PM – 12:00:00 AM 5497289703424.00"),
    ("2/01/2018 12:00:00 AM – 1:00:00 AM 5497289703424.00"),
    ("2/01/2018 1:00:00 AM – 2:00:00 AM 5497289703424.00"),
    ("2/01/2018 2:00:00 AM – 3:00:00 AM 5497289703424.00"),
    ("2/01/2018 3:00:00 AM – 4:00:00 AM 5497289703424.00"),
    ("2/01/2018 4:00:00 AM – 5:00:00 AM 5497289703424.00"),
    ("2/01/2018 5:00:00 AM – 6:00:00 AM 5497289703424.00")

    )

    $myarray | select -First 1

  • #97407

    Dougie Carson
    Participant

    Thanks but i figured it. Funny how you leave it for a while and it comes to you when you are not thinking about it 🙂

    I ended up doing
    $array | select "Date Time", "Available Capacity(RAW)", "Free Bytes(RAW)" | Where-Object {$_."Date Time" -like "*12:00:00 AM – 1:00:00 AM*"}
    This gave the one data point per day. So simple I don't know why i didn't see it earlier.

    Thanks
    Douglas

  • #97409

    Simon B
    Participant

    or you could just do
    $myarray[0]

You must be logged in to reply to this topic.