Script advice for grouping values in tables and email formatting

Welcome Forums General PowerShell Q&A Script advice for grouping values in tables and email formatting

Viewing 2 reply threads
  • Author
    Posts
    • #217239
      Participant
      Topics: 3
      Replies: 3
      Points: 31
      Rank: Member

      Hi, I’m working on a script to check the patch level of all the servers in our environment and notify the correct server application team via email,  if they have a server that hasn’t been updated in the last 90 days (We have multiple app teams that are set as server owners).

      It’s still a little rough but it seems to work.  Right now I’m just exporting the results to a CSV and catching the errors in a hash table.

      What I want to do is actually avoid exporting the results to any file and store them in a way I can format them in a table and send it. Unfortunately I’m a little bit stuck with what would be the best way to do this and looking for some advice from the forum.

      In summary I want to achieve the following.

      1. Store the results of $obj  $team  $team_email  $lastdate in a way that can be formatted  nicely in a table of  the body of an email sent with Send-MailMessage.
      2. Be able to sort this table by the email value, group and send the list of servers with the same email owner’s individually formatted tables with only their servers in the body of the email.

      What would be the best way to do this?

       

       

       

    • #217353
      Participant
      Topics: 9
      Replies: 707
      Points: 2,847
      Helping Hand
      Rank: Community Hero

      This is exactly what new-object is made for.

      If you need the object to retain the order of properties, create an ordered hashtable for the properties first.

      You can collect all the output to a variable outside the loop like this

      Or you could use an arraylist

      Once you have all of your results, group them and create your emails. Reference each property where you need it with dot notation.

      This example assumes each team email has only one team associated with it. If there are multiple teams for one email, I would change the grouping to the team name and then adjust the loops accordingly. This is the same example with @mailparams ran through write-output instead of send-mailmessage.

      https://pasteboard.co/J381xZJ.jpg

      I hope this helps out.

    • #218613
      Participant
      Topics: 3
      Replies: 3
      Points: 31
      Rank: Member

      Thanks for that. I’ve found a good solution now using a datatable

Viewing 2 reply threads
  • The topic ‘Script advice for grouping values in tables and email formatting’ is closed to new replies.