Count the number of "online" in the row "status" - csv-file

This topic contains 0 replies, has 1 voice, and was last updated by  Forums Archives 6 years, 4 months ago.

  • Author
  • #5633

    by alexej at 2013-03-06 05:29:56

    Hi 🙂

    I'm kinda new at Power Shell and I'm trying to write a script which is reading a csv-file and counting how many times it can find the word "online" at row "Status".
    If two or less "servers" are "online" there should be an output which tells you that "x" servers are online.

    server, status
    server1, offline
    server2, online
    server3, offline
    server4, offline
    server5, offline

    Message: "Pay attention. Only 1 server is online!"

    server, status
    server1, offline
    server2, online
    server3, online
    server4, online
    server5, offline

    Message]"3 servers are online."[/i]

    Another part of it would be to send that as a notification via E-Mail but I got this already.
    Sorry that I've to ask you such an easy question but I can't find a way to count it. –> (We are still using Power Shell v1.)


    by mjolinor at 2013-03-06 06:17:05

    Something like this?

    $statuslist = import-csv

    $online = $statuslist |
    where {$_.status -eq 'online'}


    by alexej at 2013-03-06 06:41:32

    Thank you, everything works fine.

    I knew that there was an easy way but I couldn't find it.

You must be logged in to reply to this topic.