PoshCode Archive  Artifact Content

Artifact e617043c13f2a3e8ca9502d19b72e851902f0aa7867cbb4eec9d04594d907df7:

  • File Show-Last-Backup-Server.ps1 — part of check-in [d037999507] at 2018-06-10 13:41:21 on branch trunk — ############################################################################################# (user: SQLDBAwithabeard size: 2230)

# encoding: utf-8
# api: powershell
# title: Show Last Backup Server
# description: #############################################################################################
# version: 0.1
# type: function
# author: SQLDBAwithabeard
# license: CC0
# function: Show-LastServerBackup
# x-poshcode-id: 4463
# x-archived: 2016-04-06T05:25:57
# x-published: 2016-09-11T19:06:00
#
# #
# NAME: Show-LastServerBackup.ps1
# AUTHOR: Rob Sewell http://sqldbawithabeard.com
# DATE:06/08/2013
# #
# COMMENTS: Load function for Showing Last Backup of each database on a server
# 覧覧覧覧覧覧覧覧覧覧覧覧
#

  #############################################################################################
#
# NAME: Show-LastServerBackup.ps1
# AUTHOR: Rob Sewell http://sqldbawithabeard.com
# DATE:06/08/2013
#
# COMMENTS: Load function for Showing Last Backup of each database on a server
# 覧覧覧覧覧覧覧覧覧覧覧覧

Function Show-LastServerBackup ($SQLServer)
{

$server = new-object "Microsoft.SqlServer.Management.Smo.Server" $SQLServer

$Results = @();

foreach($db in $server.Databases)
{
$DBName = $db.name
$LastFull = $db.lastbackupdate
if($lastfull -eq '01 January 0001 00:00:00')
{$LastFull = 'NEVER'}

$LastDiff = $db.LastDifferentialBackupDate  
if($lastdiff -eq '01 January 0001 00:00:00')
{$Lastdiff = 'NEVER'}
                                                                                                                                                        
$lastLog = $db.LastLogBackupDate 
if($lastlog -eq '01 January 0001 00:00:00')
{$Lastlog= 'NEVER'}

        $TempResults = New-Object PSObject;
        $TempResults | Add-Member -MemberType NoteProperty -Name "Server" -Value $Server;
        $TempResults | Add-Member -MemberType NoteProperty -Name "Database" -Value $DBName;
        $TempResults | Add-Member -MemberType NoteProperty -Name "Last Full Backup" -Value $LastFull;
        $TempResults | Add-Member -MemberType NoteProperty -Name "Last Diff Backup" -Value $LastDiff;
        $TempResults | Add-Member -MemberType NoteProperty -Name "Last Log Backup" -Value $LastLog;
        $Results += $TempResults;


}
$Results|Format-Table -auto
}