PowerShell Home Lab Toolkit for Backup Checks and Service Management
Create a PowerShell toolkit for backup checks, service restarts, and daily status notes in a small lab environment.
Expected Outcome
A working PowerShell toolkit that automates backup verification, service management, and daily reporting.
Assumptions
- Windows operating system (Windows 10 or later)
- PowerShell 5.1 or later
- Basic knowledge of PowerShell scripting
- Access to backup storage (e.g., Proxmox Backup Server, Windows shares)
Bill of Materials
- Computer with Windows OS
- PowerShell ISE or any code editor
- Access to backup server or storage location
- Email account for sending reports (optional)
Build Steps
- Install PowerShell Modules
Install necessary PowerShell modules for managing services and backups.
Example pattern only. Adjust for your environment before running.
Install-Module -Name PSScheduledJob -Force Install-Module -Name PSSQLite -Force
- Create Backup Check Script
Develop a PowerShell script that checks the status of backups and logs the results.
Safe to run: read-only
$backupPath = 'C:\Backups' $backupFiles = Get-ChildItem -Path $backupPath -Filter '*.bak' foreach ($file in $backupFiles) { if ($file.LastWriteTime -lt (Get-Date).AddDays(-7)) { Write-Output 'Backup file $($file.Name) is older than 7 days.' } else { Write-Output 'Backup file $($file.Name) is up to date.' } } - Create Service Restart Script
Write a script to check and restart specific services if they are not running.
Changes system state: review before running
$services = 'Spooler', 'wuauserv' foreach ($service in $services) { $serviceStatus = Get-Service -Name $service if ($serviceStatus.Status -ne 'Running') { Start-Service -Name $service Write-Output 'Service $service has been restarted.' } else { Write-Output 'Service $service is running.' } } - Create Daily Status Summary
Develop a script that compiles the results of the backup checks and service statuses into a daily summary report.
Example pattern only. Adjust for your environment before running.
$report = 'Daily Status Report' $report += 'Backup Check Results:`n' # Call backup check script here $report += 'Service Status Results:`n' # Call service restart script here Send-MailMessage -To 'user@example.com' -From 'lab@example.com' -Subject 'Daily Status Report' -Body $report -SmtpServer 'smtp.example.com'
- Schedule the Scripts
Use Task Scheduler to automate the running of the scripts daily.
Changes system state: review before running
schtasks /create /tn 'BackupCheck' /tr 'powershell.exe -File C:\Scripts\BackupCheck.ps1' /sc daily /st 09:00 schtasks /create /tn 'ServiceRestart' /tr 'powershell.exe -File C:\Scripts\ServiceRestart.ps1' /sc daily /st 09:05 schtasks /create /tn 'DailySummary' /tr 'powershell.exe -File C:\Scripts\DailySummary.ps1' /sc daily /st 09:10
Validation
- Check the output logs for backup checks and service restarts to ensure they are functioning correctly.
- Verify that the daily summary email is received and contains accurate information.
Troubleshooting
- Check service logs before changing the design.
- Confirm ports, paths, credentials, DNS names, and container names match the guide assumptions.
Cleanup or Rollback
- Stop test services you no longer need and keep a copy of working configuration before deleting volumes or data directories.
Next Improvements
- Expand the toolkit to include monitoring of additional services.
- Integrate with a more sophisticated logging system or dashboard.
- Explore backup verification methods for different platforms like Proxmox.