Advice around statistics from csv

Welcome Forums General PowerShell Q&A Advice around statistics from csv

Viewing 6 reply threads
  • Author
    Posts
    • #196619
      Participant
      Topics: 6
      Replies: 10
      Points: 103
      Rank: Participant

      Hi,

      We have a system that logs activities to a csv file and i am looking to read this CSV file and send stats out in the day.

      I import the csv file using `$logTable = Import-Csv $logFile`

      I would like to find the count of many different people, for example if i have 10 users, i can find how many activities they did by running

      I don’t feel this is the best way to be doing it though.

      I need to collect the count for 30-40 variations

      Dept 1

      Total: 0 | 22
      Service1: 0 | 6
      Service2: 0 | 4
      Service3: 0 | 0
      Service4: 0 | 12

      Breakdown By User:
      User1: 0 | 0
      User2: 0 | 15
      User3: 0 | 0

      The first number (before the pipe) is how many that day and the 2nd number is how many for the month so far

      So you can see this would mean me duplicating the code above 40 times which would be messy.

      I have the users and services stored in an array so was thinking there should be a way to loop through the arrays and save the count to a variable but not sure how to do that and also not sure if thats the correct way either as it would mean ending up with 40 variables.

      What are you thoughts on handling such task?

       

      Cheers,

      jamie

    • #196631
      Participant
      Topics: 7
      Replies: 2458
      Points: 6,439
      Helping Hand
      Rank: Community MVP

      It’s hard to give a reasonable advice without seeing your CSV data (at least a few lines with the relevant but sanitized data) and without knowing what you’re actually after. 😉

      Anyway … you should take a look at the cmdlet Group-Object. You should read the complete help including the examples to learn how to use it.

    • #196652
      Participant
      Topics: 13
      Replies: 1753
      Points: 3,136
      Helping Hand
      Rank: Community Hero

      You can provide a CSV example like so:

      This gives us a basic object to play with:
      PS

      The you can do see some examples of Olaf’s suggestion using Group-Object:

    • #196676
      Participant
      Topics: 6
      Replies: 10
      Points: 103
      Rank: Participant

      Hi,

      Thank you for your replies, i really appreciate your support and the directions you give me.

      The Group-Object cmdlet i think is the way to go with this, i have done a little bit of playing with it and hopefully will be able to make it fit however here is some extra details / csv that will help you understand what i’m trying to achieve in case there is a better way, i have also added what i currently have to the bottom of this post.

      CSV File

       

      This is how the statistics are currently output to email (based on a batch file rather than Powershell)
      It doesn’t need to stay in this format but just needs to be clear.

      The numbers below are random to show you how they output and not a reflection of the test csv data above.

      #######################
      Location 1

      Total: 0 | 22
      Service1: 0 | 6
      Service2: 0 | 4
      Service3: 0 | 0
      Service4: 0 | 12

      Breakdown By User:
      User1: 0 | 0
      User2: 0 | 15
      User3: 0 | 0
      User4: 0 | 0

      #######################
      Location 2

      Total: 0 | 22
      Service1: 0 | 6
      Service2: 0 | 4
      Service3: 0 | 0
      Service4: 0 | 12

      Breakdown By User:
      User1: 0 | 0
      User2: 0 | 15
      User3: 0 | 0
      User4: 0 | 0

      #######################

      Forgetting the format of the output for now, i can pretty much get what i’m after with group-object with the following code

      This matches today’s date which is good for the first number 0|0 but to get the 2nd number 0|0 i need to search for any records matching $currentMonth

       

      Can you advise if this is the best way to collect such data and how i would get currentMonth

       

      Regards,

      Jamie

    • #196955
      Participant
      Topics: 6
      Replies: 10
      Points: 103
      Rank: Participant

      Hi Olaf and Rob,

      I appreciate your replies, they have helped a lot however my original reply that i tried to post 2 days ago still isn’t showing up but i can’t post it again as it says i have already said that so hopefully my reply with a detailed response will show or be approved soon.

      Regards,
      Jamie

    • #196958
      Participant
      Topics: 7
      Replies: 2458
      Points: 6,439
      Helping Hand
      Rank: Community MVP

      You may open a ticket about this in the feedback forum: https://powershell.org/forums/forum/community-discussion-site-feedback/

    • #196976
      Participant
      Topics: 6
      Replies: 10
      Points: 103
      Rank: Participant
Viewing 6 reply threads
  • The topic ‘Advice around statistics from csv’ is closed to new replies.