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

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

Hi :slight_smile:

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.

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


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

or
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.)

alexej
by mjolinor at 2013-03-06 06:17:05
Something like this?

$statuslist = import-csv <path to .csv file>

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

$online.count
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.