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:
- Login Target Azure Tenant (Record error if happen)
- Take VM Snapshot (Record error if happen)
- Delete VM Specific File (Record error if happen)
- Housekeeping job – Snapshot Retention (Record error if happen)
- Housekeeping job – PowerShell Log Retention (Record error if happen)
- Send Summary Report by Email
Step 1 – Login Target Azure Tenant (Record error if happen)
![](/wp-content/uploads/2022/08/1-5.png)
Step 2 – Take VM Snapshot (Record error if happen)
![](/wp-content/uploads/2022/08/2-6.png)
Step 3 – Delete VM Specific File (Record error if happen)
![](/wp-content/uploads/2022/08/3-3.png)
Step 4 – Housekeeping job – Snapshot Retention (Record error if happen)
![](/wp-content/uploads/2022/08/4-2.png)
Step 5 – Housekeeping job – PowerShell Log Retention (Record error if happen)
![](/wp-content/uploads/2022/08/5-1.png)
Step 6 – Send Summary Report by Email
![](/wp-content/uploads/2022/08/6-1.png)
![](/wp-content/uploads/2022/08/7-1.png)
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
![](https://soshk.com/wp-content/uploads/2020/11/SOS_Logo_vit_white-1024x1024-1-150x150.png)
Eric Chan
Microsoft MVP
SOS Group Limited