If you found the information helpful, please consider supporting us by donating a coffee to help keep this website alive. Your contribution is greatly appreciated!
Automated Backup Reports for Windows Machines: A Comprehensive Guide
Part I Computer Setup
In today’s data-driven world, maintaining robust backup systems is essential to safeguarding critical information. Automating backup reports for Windows machines not only ensures data integrity but also provides clients with transparency and peace of mind. In this guide, I’ll walk you through the setup process step by step, highlighting the tools and techniques involved.
The core concept of this project revolves around enhancing the backup reporting service provided by the company I’m associated with. While our company already sends out email notifications to users, primarily managers, upon the completion or encountering issues during backup processes, we’ve identified an opportunity to offer additional insight and transparency. To address this, we’ve begun sending out comprehensive spreadsheets to select clients. These spreadsheets detail each machine and server, providing crucial information such as the date of the last backup, the contents included in the backup, and the scheduled time for the next backup session. This initiative aims to empower clients with a clear understanding of their backup status, fostering trust and reliability in our services.
What you need
- Windows Backup: Utilizing the built-in Windows backup functionality.
- Task Manager: Orchestrating tasks based on event triggers.
- Email Services: Leveraging Gmail and Outlook for email notifications.
- Power Automate: Automating tasks and processes.
- Excel: Organizing and visualizing backup reports.
- Scripting (PowerShell): Automating actions based on event triggers.
In configuring our computer/server setup (windows server 2012 R2 in our scenario), the initial step involves enabling/setting up Windows Backup. Once this foundational setup is complete, our focus shifts to creating a script tailored to send event information to Outlook.
Script Code
Function Send-Email($Subject, $Body) {
$SMTPServer = “insert smtp server here”
$SMTPPort = “587”
$From = “insert here the gmail account or the account which is used to send emails from”
$To = “email where you send to”
$Username = “username you are using to send email”
$SecurePassword = Get-Content C:\Scripts\securepassword.txt | ConvertTo-SecureString
$Credential = New-Object System.Management.Automation.PSCredential ($Username, $SecurePassword)
Send-MailMessage -From $From -To $To -Subject $Subject -Body $Body -SmtpServer $SMTPServer -Port $SMTPPort -Credential $Credential -UseSsl
}
try {
$event = Get-WinEvent -FilterHashtable @{LogName=’Microsoft-Windows-Backup’; ProviderName=’Microsoft-Windows-Backup’} -MaxEvents 2
Write-Host “Fetched event with ID $($event.Id)”
}
catch {
Write-Host “An error occurred while fetching the Microsoft-Windows-Backup event.”
Send-Email “Server – Error Fetching Backup Event” “An error occurred while fetching the Microsoft-Windows-Backup event.”
exit 1
}
$successfulEventId = 4
$failedEventId = 5
if ($event.Id -eq $successfulEventId) {
Send-Email “Server – Windows Server Backup Is Successful” “$($event.Message)”
} elseif ($event.Id -eq $failedEventId) {
Send-Email “Server – Windows Server Backup – FAILED” “$($event.Message)”
} else {
Send-Email “Server – Unknown Backup Event” “$($event.Message)”
}
Please copy the provided code and save it with a name of your choice, ensuring it bears the .ps1 extension. For instance, I’ve chosen to save the script as “backupnotif.ps1” in the directory C:\Scripts. Additionally, execute the following script to generate a secure password for your Google email account or whichever account you use to dispatch emails to the Outlook account. Feel free to customize the code according to your preferences. In this particular scenario, the script will prompt you to input the password, which will then be encrypted and saved in encoded format within C:\Scripts\securepassword.txt. It’s important to note that the securepassword.txt file is tied to one computer due to its reliance on the Read-Host argument. If you intend to utilize it on another computer, you must rerun the script on that specific machine. This method ensures the confidentiality and security of your email credentials while streamlining the setup process for enhanced functionality.
Secure Password Powershell Command
Read-Host -Prompt “Enter your password” -AsSecureString | ConvertFrom-SecureString | Out-File -FilePath “C:\Scripts\securedpassword.txt”
In finalizing the setup for our computer/server, the pivotal last steps involve configuring two tasks within the Task Scheduler. The initial task we establish is designed to address backup failures effectively. Firstly, under the General tab, it’s imperative to ensure that the task runs irrespective of whether a user is logged in and to enable the “Run with highest privileges” option for enhanced functionality. Transitioning to the Triggers tab, click on “New” to initiate a new trigger based on a specific event. In this case, for Windows Server 2012 R2, the event to trigger the task is identified by the Log: Microsoft-Windows-Backup/Operational and ID: 4. For further insights on how to locate event IDs specific to your Windows version, I encourage you to access this link which offers detailed guidance on event ID identification based on Windows versions.
To configure the task for successful backups, we’ll need to create a custom XML query. Begin by creating a new task and assigning it a name of your choice, such as “Successful Backup.” Maintain the same settings under the Actions tab as in the previous task. The key difference lies in the Trigger tab. Here, select “Custom” and proceed to “Edit Event Filter.” Check the “Edit XML” tab and select “Edit query manually” to view and adjust the XML query as needed. The provided query ensures that the task triggers upon successful backup events. Feel free to modify the query to align with your specific requirements, tailoring it to capture the events relevant to your system’s backup success criteria.
XML Query for Successful backup trigger
<QueryList>
<Query Id=”0″ Path=”Microsoft-Windows-Backup”>
<Select Path=”Microsoft-Windows-Backup”>*[System[(EventID=5 or EventID=8 or EventID=9 or (EventID >= 17 and EventID <= 22) or EventID=49 or EventID=50 or EventID=52 or EventID=100 or EventID=517 or EventID=518 or EventID=521 or EventID=527 or EventID=528 or EventID=544 or EventID=545 or EventID=546 or EventID=561 or EventID=564 or EventID=612)]]</Select>
</Query>
</QueryList>
Part II Cloud Setup
In the final phase of our setup, we focus on configuring rules within Power Automate to automate the entire process seamlessly. Navigate to https://make.powerautomate.com/ and either log in or sign up if you haven’t already. On the left-hand side, select “Create” and then choose “Automated cloud flow.” Assign a meaningful name to the flow, such as “Client Name – Machine Name” (e.g., Apple – DC-server).
Utilize the search bar to find “Outlook” in the trigger field and select “{when an email arrives (v3)}.” Within the mailbox where reports arrive, ensure you’ve created a folder named “Backup Notifications” and configured a rule to route emails from the designated Gmail account into this folder.
Next, click on the plus sign and search for “Compose” under Data operation. Insert the following query: first(split(triggerOutputs()?[‘headers’][‘Subject’], ‘ – ‘)). This step extracts the client’s name from the email subject.
In Power Automate, configure the following attributes: the folder is “Backup notifications,” ensuring Power Automate scans only that folder. If an email arrives from ‘notifications@gmail.com’ (example), it checks the subject. If the subject includes the customer’s name (e.g., Apple – Server Backup Successfully), Power Automate creates a new row in the spreadsheet and copies everything from the body of the email.
Next, add a condition: if true, add the action “Add row into a table.” Create an Excel spreadsheet in SharePoint (e.g., Contorso > Documents > Clients > Client1 > Reports > Backup Reports.xlsx). Select the appropriate table based on your organizational structure.
Leave the condition if false blank. Then, create another step. If the email subject equals “test – Windows Server Failed,” create a new row in the table with information from the body of the email.
Refer to the images provided for visual guidance on the setup process. This comprehensive automation streamlines backup reporting, enhancing efficiency and ensuring timely responses to critical events.
If you found the information helpful, please consider supporting us by donating a coffee to help keep this website alive. Your contribution is greatly appreciated!
Hi Everyone, please let me know your toughs about this project or if you have any questions!
Thanks a lot!