Help with SureBackup File validation script please.
Please don't ask me why my auditors want this, but here goes. My SureBackups run on the same day as my backups, right after the last backup is complete. It never crosses into the next day.
I have a daily scheduled task on each VM to write to a text file with today's date in YYYYMMDD format in the content. I'm trying to get my SureBackup script testing to check the file contents and validate that the contents match, but I'm not sure my output is what it's looking for and also if the Write-Host may be mucking it up?
$FilePath = 'C:\Temp\SureBackupValidation.txt'
$Return = 1
# Fail if the file doesn't exist
if (-not (Test-Path $FilePath)) {
Write-Host "Validation file not found."
$Return = 1 #Somewhat redundant
exit $Return
}
# Read the file contents
$FileDate = (Get-Content $FilePath -ErrorAction SilentlyContinue | Select-Object -First 1).Trim()
# Get today's date in the expected format
$Today = Get-Date -Format 'yyyyMMdd'
if ($FileDate -eq $Today) {
Write-Host "Validation successful. File contains today's date: $Today"
$Return = 0
exit $Return
}
else {
Write-Host "Validation failed. Expected: $Today, Found: $FileDate"
exit $Return
}