Public/Get-MSPLastBackupStatus.ps1

Function Get-LastMSPBackupStatus {
    <#
        .SYNOPSIS
            Check the last status of the MSP Backup
        .DESCRIPTION
            Check the last status of the MSP Backup
        .PARAMETER DataSource
            Shows the status of a specific datasource, valid options are:
            BareMetalRestore, Exchange, FileSystem, MySql, NetworkShares, Oracle, SystemState, VMware, VssHyperV, VssMsSql, VssSharePoint
        .PARAMETER Total
            Shows the status of the Total counter, if this is not 5 atleast 1 back-up has failed
        .EXAMPLE
            [PS] C:\>Get-LastMSPBackupStatus -DataSource SystemState
 
            TimeStamp Status
            --------- ------
            1542750127 5
 
            -DataSource Shows the status of a specific datasource, valid options are:
            BareMetalRestore, Exchange, FileSystem, MySql, NetworkShares, Oracle, SystemState, VMware, VssHyperV, VssMsSql, VssSharePoint
 
            The TimeStamp is always returned as a UnixTimeStamp
 
        .EXAMPLE
            [PS] C:\>Get-LastMSPBackupStatus -Total
 
            TimeStamp Status
            --------- ------
            1542750127 5
 
            Shows the status of the Total counter, if this is not 5 atleast 1 back-up has failed
 
            The TimeStamp is always returned as a UnixTimeStamp
        .LINK
            about_Functions_Advanced
        .LINK
            about_CommonParameters
    #>

    [CmdletBinding(DefaultParameterSetName = "DataSource")]
    Param(
        [Parameter(Mandatory = $True, ParameterSetName = "DataSource")]
        [ValidateSet("BareMetalRestore", "Exchange", "FileSystem", "MySql", "NetworkShares", "Oracle", "SystemState", "VMware", "VssHyperV", "VssMsSql", "VssSharePoint")]
        [string]$DataSource,
        [Parameter(ParameterSetName = "Total")]
        [switch]$Total
    )
    Begin {
        $xml = New-Object XML
        $xml.load($Script:StatusReport)
    }
    Process {
        If ($DataSource) {
            Switch ($DataSource) {
                BareMetalRestore {
                    $LastSessionStatus = $xml.Statistics.'PluginBMR-Restore-LastSessionStatus'
                    $LastSessionTimeStamp = $xml.Statistics.'PluginBMR-Restore-LastSessionTimestamp'
                }
                Exchange {
                    If ($xml.Statistics.'PluginSlExchange-LastSessionStatus' -ne "") {
                        $LastSessionStatus = $xml.Statistics.'PluginSlExchange-LastSessionStatus'
                        $LastSessionTimeStamp = $xml.Statistics.'PluginSlExchange-LastSessionTimestamp'
                    } Else {
                        $LastSessionStatus = $xml.Statistics.'PluginExchangeOnline-LastSessionStatus'
                        $LastSessionTimeStamp = $xml.Statistics.'PluginExchangeOnline-LastSessionTimestamp'
                    }
                }
                FileSystem {
                    $LastSessionStatus = $xml.Statistics.'PluginFileSystem-LastSessionStatus'
                    $LastSessionTimeStamp = $xml.Statistics.'PluginFileSystem-LastSessionTimestamp'
                }
                MySql {
                    $LastSessionStatus = $xml.Statistics.'PluginMySql-LastSessionStatus'
                    $LastSessionTimeStamp = $xml.Statistics.'PluginMySql-LastSessionTimestamp'
                }
                NetworkShares {
                    $LastSessionStatus = $xml.Statistics.'PluginNetworkShares-LastSessionStatus'
                    $LastSessionTimeStamp = $xml.Statistics.'PluginNetworkShares-LastSessionTimestamp'
                }
                Oracle {
                    $LastSessionStatus = $xml.Statistics.'PluginOracle-LastSessionStatus'
                    $LastSessionTimeStamp = $xml.Statistics.'PluginOracle-LastSessionTimestamp'
                }
                SystemState {
                    If ($xml.Statistics.'PluginSystemState-LastSessionStatus' -ne "") {
                        $LastSessionStatus = $xml.Statistics.'PluginSystemState-LastSessionStatus'
                        $LastSessionTimeStamp = $xml.Statistics.'PluginSystemState-LastSessionTimestamp'
                    } Else {
                        $LastSessionStatus = $xml.Statistics.'PluginVssSystemState-LastSessionStatus'
                        $LastSessionTimeStamp = $xml.Statistics.'PluginVssSystemState-LastSessionTimestamp'
                    }
                }
                VMware {
                    $LastSessionStatus = $xml.Statistics.'PluginVMWare-LastSessionStatus'
                    $LastSessionTimeStamp = $xml.Statistics.'PluginVMWare-LastSessionTimestamp'
                }
                VssHyperV {
                    $LastSessionStatus = $xml.Statistics.'PluginVssHyperV-LastSessionStatus'
                    $LastSessionTimeStamp = $xml.Statistics.'PluginVssHyperV-LastSessionTimestamp'
                }
                VssMsSql {
                    If ($xml.Statistics.'PluginMsSql-LastSessionStatus' -ne "") {
                        $LastSessionStatus = $xml.Statistics.'PluginMsSql-LastSessionStatus'
                        $LastSessionTimeStamp = $xml.Statistics.'PluginMsSql-LastSessionTimestamp'
                    } Else {
                        $LastSessionStatus = $xml.Statistics.'PluginVssMsSql-LastSessionStatus'
                        $LastSessionTimeStamp = $xml.Statistics.'PluginVssMsSql-LastSessionTimestamp'
                    }
                }
                VssSharePoint {
                    $LastSessionStatus = $xml.Statistics.'PluginVssSharePoint-LastSessionStatus'
                    $LastSessionTimeStamp = $xml.Statistics.'PluginVssSharePoint-LastSessionTimestamp'
                }
            }
        }
    }
    End {
        If ($Total) {
            $LastSessionStatus = $xml.Statistics.'PluginTotal-LastSessionStatus'
            $LastSessionTimeStamp = $xml.Statistics.'PluginTotal-LastSessionTimestamp'
        }
        If ($DataSource) {
            If ($LastSessionStatus -eq "") {
                $LastSessionStatus = $null
                $LastSessionTimeStamp = $null
            }
        }
        $LastSessionInfo = @{
            Status    = $LastSessionStatus
            TimeStamp = $LastSessionTimeStamp
        }

        $Result = New-Object psobject -Property $LastSessionInfo
        Return $Result
    }
}