There is a new Version of my SCDPM PowerShell Script, Check Last Backup. I have added a high requested Feature, to skip Hyper-V Datasources.
Why you want to skip VM Backup? My Script is starting a Backup job if your backup is too old, so cause Hyper-V VM’s can sometime backed up in Offline mode, that is not good if this is happening during production time.
So the Script has now the possibility to skip Hyper-V VM Datasources.
Like the previous Version, you can call this Script with Parameter’s and send the Result as an email.
The Script
At the beginning is a list of Parameter’s.
#Parameter
Param(
[Parameter(Mandatory=$false)][string]$DPMServerName,
[Parameter(Mandatory=$false)][string]$Spandays,
[Parameter(Mandatory=$false)][switch]$Checkonly,
[Parameter(Mandatory=$false)][switch]$SkipHyperV,
[Parameter(Mandatory=$false)][switch]$LogPublic,
[Parameter(Mandatory=$false)][switch]$SendLogFile,
[Parameter(Mandatory=$false)][string]$SMTPServer,
[Parameter(Mandatory=$false)][string]$SMTPSender,
[Parameter(Mandatory=$false)][string]$SMTPTo
)
#Import Modules
Import-Module dataprotectionmanager
#Testing
#$LogPublic=$true
#$Checkonly=$true
#$SkipHyperV=$true
#$SendLogFile=$True
#$SMTPServer="ExchangeServer01"
#$SMTPSender="DPM_Alerts@techguy.at"
#$SMTPTo="michael@techguy.at"
#Standard Parameters if empty
if (!($DPMServerName)){$DPMServerName=$env:COMPUTERNAME}
if (!($Spandays)){$Spandays="3"}
Now the logging and connection to SCDPM Server
$Log=@()
Get-Datasource -DPMServerName $DPMServerName | Out-Null
$DS=Get-Datasource -DPMServerName $DPMServerName | where {$_.CurrentProtectionState -eq "Protected"}
$Date=Get-Date -format d ((Get-Date).adddays(-$Spandays))
$Footer="
`r`n
`r`n
Script powered by www.techguy.at
Find more Information at https://www.techguy.at/tag/checklastbackups/
"
#Functions
Function Write-Log ($Text) {
# Write Log to PS if $LogPublic is Yes
if ($LogPublic) {
if ($Text -match "INFO:") {
Write-Host $Text -ForegroundColor Green
} elseif ($Text -match "WARNING:") {
Write-Host $Text -ForegroundColor Yellow
} elseif ($Text -match "ERROR:") {
Write-Host $Text -ForegroundColor Red
} else {
Write-Host $Text
}
}
return $Text
}
Function Query-DSJobs ($DS) {
# Query DS if there is an active Job
if ((Get-DPMJob -Datasource $DS -Status InProgress).count -ne 0) {
$Log+=Write-Log "WARNING: There is a running Job for DS: $DS.Name"
return $False
} else {
$Log+=Write-Log "INFO: No running Jobs for DS: $DS.Name"
return $True
}
}
At the end there is the magic.
Foreach ($Entry in $DS) {
$Entry
if ($Entry.ObjectType -eq "Microsoft Hyper-V" -and $SkipHyperV)
{
$Log+=Write-Log "Warning: Skip HyperV $Entry"
}
else
{
$RP=Get-RecoveryPoint -Datasource $Entry | Sort-Object BackupTime -Descending
if ($RP.count -gt 0) {
$CompareDate=Get-date($RP[0].BackupTime) -format d
$Span=New-TimeSpan -Start $CompareDate -End $Date
if ($Span.Days -gt 0) {
$Log+=Write-Log "Error: $CompareDate, $Date, $Entry"
if ($Entry.State -eq "Invalid") {
if (!($Checkonly)) {if (Query-DSJobs $Entry) {Start-DPMDatasourceConsistencyCheck -Datasource $Entry}}
} else {
if (!($Checkonly)) {if (Query-DSJobs $Entry) {New-RecoveryPoint -Datasource $Entry -Disk -BackupType expressfull –WithDataIntegrityCheck -Verbose}}
}
} else {
$Log+=Write-Log "Info: $CompareDate, $Date, $Entry"
}
} elseif ($RP.count -eq 0) {
$Log+=Write-Log "Error: no Recoverpoint $Entry"
if (!($Checkonly)) {if (Query-DSJobs $Entry) {Start-DPMDatasourceConsistencyCheck -Datasource $Entry}}
}
}
}
if ($SendLogfile)
{
$Mailtext=$Log -join "`r`n"
$Mailtext=$Mailtext+ $Footer
Send-MailMessage -From $SMTPSender -SmtpServer $SMTPServer -To $SMTPTo -Subject "RP Status from $DPMServerName" -Body $Mailtext
}
Some Screenshots
TechNet Gallery Download
You can download this Script at the TechNet Gallery: https://gallery.technet.microsoft.com/Check-DPM-for-last-96f12c86
Let me know if you have some Questions.
All my other TechNet Gallery Downloads are here: http://bit.ly/1jrYQoA
PLEASE RATE MY DOWNLOADS AND LET ME KNOW ABOUT YOUR IDEAS FOR THE NEXT VERSION.
Michael Seidl aka Techguy


