<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Edwin M SarmientoCheck the last backup date in SQL Server using Windows PowerShell &#8211; Edwin M Sarmiento</title>
	<atom:link href="https://www.edwinmsarmiento.com/check-the-last-backup-date-in-sql-server-using-windows-powershell/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.edwinmsarmiento.com</link>
	<description>Intentional Excellence</description>
	<lastBuildDate>Mon, 13 Apr 2026 21:00:49 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	
<site xmlns="com-wordpress:feed-additions:1">84283043</site>		<item>
		<title>Check the last backup date in SQL Server using Windows PowerShell</title>
		<link>https://www.edwinmsarmiento.com/check-the-last-backup-date-in-sql-server-using-windows-powershell/</link>
		<comments>https://www.edwinmsarmiento.com/check-the-last-backup-date-in-sql-server-using-windows-powershell/#respond</comments>
		<pubDate>Tue, 16 Jun 2009 23:32:00 +0000</pubDate>
		<dc:creator>Edwin M Sarmiento</dc:creator>
				<category><![CDATA[last backup date]]></category>
		<category><![CDATA[modify SQL Server logins]]></category>
		<category><![CDATA[Windows PowerShell]]></category>
		<guid isPermaLink="false">http://bassplayerdoc.wordpress.com/2009/06/16/check-the-last-backup-date-in-sql-server-using-windows-powershell</guid>

				<description><![CDATA[This article highlights how to use Windows PowerShell to retrieve database properties using SMO. Notice how easy it is to check the database properties using pretty common syntax One of the challenges I have when I was starting out as a SQL Server DBA was to check for the last backup date for a database. [&#8230;]]]></description>
					<content:encoded><![CDATA[<p><span style="font-family:arial;">This <a href="http://mssqltips.com/tip.asp?tip=1759">article </a>highlights how to use Windows PowerShell to retrieve database properties using SMO. Notice how easy it is to check the database properties using pretty common syntax</span></p>
<p>One of the challenges I have when I was starting out as a SQL Server DBA was to check for the last backup date for a database. One way to do this is to find out which tables in the MSDB database contain the records of the backup history. What&#8217;s really challenging here is the fact that you would have to look at the tables and their corresponding relationships which, apparently, MSDB doesn&#8217;t have. You simply have to rely on what SQL Server Books Online has to say. Plus, the MSDB database will only contain records for databases with backups. What about those without?</p>
<p>For SQL Server 2005, the script below displays the last backup date of all the databases on your SQL Server instance. This script is from the <a href="http://code.msdn.microsoft.com/SQLExamples/Wiki/View.aspx?title=LastBackUpDate">MSDN Code Gallery</a></p>
<p><code style="font-size:12px;"><span style="color:blue;">SELECT<br />
</span><span style="color:black;">T1.Name </span><span style="color:blue;">AS </span><span style="color:black;">DatabaseName</span><span style="color:gray;">,<br />
</span><span style="color:magenta;">COALESCE</span><span style="color:gray;">(</span><span style="color:magenta;">CONVERT</span><span style="color:gray;">(</span><span style="color:blue;">VARCHAR</span><span style="color:gray;">(</span><span style="color:black;">12</span><span style="color:gray;">), </span><span style="color:blue;">MAX</span><span style="color:gray;">(</span><span style="color:black;">T2.backup_finish_date</span><span style="color:gray;">), </span><span style="color:black;">101</span><span style="color:gray;">),</span><span style="color:red;">'Not Yet Taken'</span><span style="color:gray;">) </span><span style="color:blue;">AS </span><span style="color:black;">LastBackUpTaken</span><span style="color:black;"><br />
</span><span style="color:blue;">FROM </span><span style="color:black;">sys.sysdatabases T1 </span><span style="color:magenta;">LEFT </span><span style="color:gray;">OUTER </span><span style="color:blue;">JOIN </span><span style="color:black;">msdb.dbo.backupset T2<br />
</span><span style="color:blue;">ON </span><span style="color:black;">T2.database_name </span><span style="color:blue;">= </span><span style="color:black;">T1.name<br />
</span><span style="color:blue;">GROUP BY </span><span style="color:black;">T1.Name<br />
</span><span style="color:blue;">ORDER BY </span><span style="color:black;">T1.Name<br />
</span></code><br />
<span style="font-family:arial;">You can simply replace the <span style="font-size:85%;"><span style="font-weight:bold;">sys.sysdatabases</span></span> table with <span style="font-size:85%;"><span style="font-weight:bold;">master.dbo.sysdatabases</span></span> for SQL Server 2000</span></p>
<p>Below is the equivalent script using Windows PowerShell.</p>
<pre class="brush: powershell; title: ; notranslate">
$instance=&amp;quot;Your_SQL_Server_Instance_Name&amp;quot;
&#x5B;System.Reflection.Assembly]::LoadWithPartialName('Microsoft.SqlServer.SMO')| out-null

# Create an SMO connection to the instance
$s = new-object ('Microsoft.SqlServer.Management.Smo.Server') $instance

$dbs = $s.Databases
$dbs | select Name,LastBackupDate, LastLogBackupDate | format-table -autosize
</pre>
<p>The only thing to note here are the last two lines &#8211; the one that creates an instance of the database object and the one that displays and formats a few of the database object properties. The first few lines will be the same for just about any PowerShell script that will access SQL Server using SMO</p>
<div class="blogger-post-footer"><img decoding="async" src="" alt="" width="1" height="1" /></div>
]]></content:encoded>
			

		<wfw:commentRss>https://www.edwinmsarmiento.com/check-the-last-backup-date-in-sql-server-using-windows-powershell/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
				<post-id xmlns="com-wordpress:feed-additions:1">192</post-id>	</item>
	</channel>
</rss>