Send a Regular Email Containing a Datamining Report

Modified on Wed, 08 May 2024 at 02:56 PM

TABLE OF CONTENTS

Introduction

The article shows how to setup a scheduled email containing a Datamining Report, either as an attachement, or embedded in the email.


1. Create the Datamining report

  • Create the required Datamining Report
  • Perform any sorting, filtering, reordering and removing of columns in the DMR so that only the columns/rows you want to display in the report remains
  • Click Run Datamining Report
  • Save the DMR
  • Take a note of the Report Id in the window title. E.g 26


2. Create the Email Template

  • Click Administration ->PS Scripts, Emails, Buttons
  • Untick Scripts and Buttons

  • Click on the current project name such as ManagementStudio, or in this example Windows 11 (1)
  • Click here to add new item (2)

  • Give the email template a meaningful name and a subject
  • In the Email column add an email address (or a semicolon separated list of email addresses) to the CC field. Note that this could also be a distribution group email
  • Click the the Edit button (the scroll icon)
  • Add text to appear at the start of the email such as: Here is the ManagementStudio Datmining report:
  • To embed the report content as a table in the email add this line:

[MODULE-DMR-XX-ScopeDMR-AsTable]

  • To add the report as a file attachment in the email add this line:

[MODULE-DMR-XX-ScopeDMR-AsAttachment]


Where XX refers to the Datamining Report ID and MODULE refers to the appropriate module:

  • Applications
  • UserMigrations
  • Devices
  • Mailboxes
  • BespokeModule
  • DeploymentUnits
  • Defects
  • Tasks

For example:


  • If the report was embedded in the email, it's recommended to add borders to the table. To do this add the text below to the start of the email template, with the content underneath:
<style>
table.table {  
     border:solid 1px #c0c0c0;
     border-collapse: collapse;
}
     
tbody th, tbody td, thead th {
     padding: 3px;
     border-width: 1px;
     border-style: solid;
     border-color: #c0c0c0;
     vertical-align: top;
     font-size: 12px;
}
 
thead th {
    text-align: center
}
</style>

For example:


  • Click Save Changes
  • Take a note of the email template Id, which can be found in the last column.

3. Create a PowerShell script to send the email

  • Untick the Emails option, tick the Scripts option

  • Click on the current Project name, then Click here to add new item
  • Give the script a meaningful name
  • Click the the Edit button (the scroll icon)
  • Add the following line
Send-MSEmails -Module ManagementStudio -ToIds 1 -EmailTemplateId YYY -SpreadOverHours 0
  • Replace YYY with the Email template ID noted from earlier
  • Use the Grid Column Chooser to show the Grant Access 2 column
  • Add the Project Admins role to Grant Access 2
  • Schedule the PowerShell Script to run as required, e.g. every Monday at 12pm, this is when the email will be sent out automatically
  • Click Save Changes

4. Test the Script

  • Click the play button to test the script
  • An email will be sent with the DMR


Further Support

If you require further support, please visit ManagementStudio's Service Desk to search the knowledge base or create a new support ticket.