M365Buddy
PowerShell · Power Automate · Microsoft 365

Email PowerShell Reports Using Power Automate

Use a Power Automate flow to email a PowerShell-generated CSV without putting SMTP configuration in the script.

Where this fits: This is the email-delivery option for the SharePoint Site Inventory script.

When should you use Power Automate?

Use this approach when your organization already approves Power Automate and the Microsoft 365 Outlook connector, and you want PowerShell to generate the CSV while the flow handles email delivery.

Recommended architecture

PowerShell
   ↓
Generate SharePoint CSV
   ↓
Save CSV to an approved SharePoint document library
   ↓
Power Automate trigger
   ↓
Get file content
   ↓
Microsoft 365 Outlook — Send an email (V2)
   ↓
Recipients receive the CSV

Create the flow step by step

1. Create an automated cloud flow

In Power Automate, select Create → Automated cloud flow. Give the flow a name such as SharePoint Site Inventory Email.

For the trigger, select When a file is created (properties only) from the SharePoint connector.

2. Configure the SharePoint trigger

Select the SharePoint site that will receive the generated CSV and select the document library. If you want only the inventory report to trigger the flow, use a dedicated folder such as Reports/SharePointSiteInventory.

Tip: Have the PowerShell script write the CSV into this exact folder after Export-Csv.

3. Add a condition for the report file

Add Condition and check the file name or path so unrelated files do not trigger the email. For example, match a filename containing SharePoint and Inventory.

4. Get the file content

Add the SharePoint action Get file content. Use the file identifier from the trigger.

5. Send the email

Add Microsoft 365 Outlook → Send an email (V2).

  • To: enter the recipients or a distribution group.
  • Subject: for example SharePoint Site Inventory Report.
  • Body: explain that the latest CSV is attached.
  • Under Attachments, set the attachment name to the file name from the trigger.
  • Set the attachment content to the output of Get file content.

6. Optional: archive or move the report

After the email succeeds, add Move file or another approved SharePoint action if you want to archive reports by date.

What changes in the PowerShell script?

Keep the inventory collection and Export-Csv sections. Remove the SMTP variables and the Send-MailMessage block. Set the CSV output path to the local/synced or upload location used by your approved automation design.

# Keep:
$Report | Export-Csv -Path $OutputCsv -NoTypeInformation

# Remove:
# $SmtpServer
# Send-MailMessage
# SMTP credentials

Save the script and run it normally

Once the flow is saved and tested, save the modified .ps1 and run it exactly as described in the Site Inventory article.

cd "C:\Scripts\SharePoint"
.\SharePoint_Site_Inventory.ps1

The script creates the CSV. The flow detects the file and sends the email.

Test the complete chain

  1. Run the PowerShell script manually.
  2. Confirm the CSV appears in the configured SharePoint folder.
  3. Open Power Automate and confirm the flow run succeeds.
  4. Confirm the email arrives with the CSV attached.
  5. Only then schedule the PowerShell process.

Security and governance

  • Use an approved SharePoint library with appropriate permissions.
  • Use an approved Power Automate connection/service account if required.
  • Do not store passwords in the script.
  • Restrict access to reports if they contain sensitive site information.

Related Article

Return to the SharePoint Site Inventory article to configure, run and troubleshoot the report.

M365Buddy · Microsoft 365 · PowerShell · PowerShell · Power Automate · Microsoft 365