Azure Custom PowerShell Script – Take Snapshot with Retention / Delete Specific VM File / Send Email Notification

You can make a custom PowerShell script to take an Azure Snapshot with Retention period, mount a network drive to delete a specific VM folder, and keep track every step to record the error then send a summary email report daily.

This post will guide you the detailed PowerShell command.

The custom script includes the steps for the whole process automatically:

  1. Login Target Azure Tenant (Record error if happen)
  2. Take VM Snapshot (Record error if happen)
  3. Delete VM Specific File (Record error if happen)
  4. Housekeeping job – Snapshot Retention (Record error if happen)
  5. Housekeeping job – PowerShell Log Retention (Record error if happen)
  6. Send Summary Report by Email

Step 1 – Login Target Azure Tenant (Record error if happen)

Step 2 – Take VM Snapshot (Record error if happen)

Step 3 – Delete VM Specific File (Record error if happen)

Step 4 – Housekeeping job – Snapshot Retention (Record error if happen)

Step 5 – Housekeeping job – PowerShell Log Retention (Record error if happen)

Step 6 – Send Summary Report by Email

You can visit our SOS GitHub for downloading the source code as a template:https://github.com/SOSHKMVP/AzurePowerShell/blob/main/Take%20Snapshot%20with%20Retention/TakeSnap_With_Retention.ps1

Eric Chan
| + posts

Microsoft MVP
SOS Group Limited

Leave a comment

SOS Group Limited © 2024. All Rights Reserved.