<?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>Kyle Burwell, Author at SQL Solutions Group</title>
	<atom:link href="https://sqlsolutionsgroup.com/author/kburwell/feed/" rel="self" type="application/rss+xml" />
	<link>https://sqlsolutionsgroup.com/author/kburwell/</link>
	<description></description>
	<lastBuildDate>Wed, 15 Jul 2026 13:09:29 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=7.0.3</generator>

<image>
	<url>https://sqlsolutionsgroup.com/wp-content/uploads/2021/01/cropped-SSG_FAVICON0002-32x32.png</url>
	<title>Kyle Burwell, Author at SQL Solutions Group</title>
	<link>https://sqlsolutionsgroup.com/author/kburwell/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>&#8220;Is anyone still using this database?&#8221; How to find stagnant databases</title>
		<link>https://sqlsolutionsgroup.com/finding-stagnant-databases/</link>
		
		<dc:creator><![CDATA[Kyle Burwell]]></dc:creator>
		<pubDate>Tue, 14 Jul 2026 18:45:12 +0000</pubDate>
				<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL Group]]></category>
		<category><![CDATA[SQL Server]]></category>
		<guid isPermaLink="false">https://sqlsolutionsgroup.com/?p=8138</guid>

					<description><![CDATA[<p>“Is anyone still using this database?” I have been asked this question a surprising number of times lately. The answer can be trickier to find than you would think, because, by default, SQL Server doesn’t keep track. But there is a way to find stagnant databases. Worth a shot. Getting the latest user activity from [&#8230;]</p>
<p>The post <a href="https://sqlsolutionsgroup.com/finding-stagnant-databases/">&#8220;Is anyone still using this database?&#8221; How to find stagnant databases</a> appeared first on <a href="https://sqlsolutionsgroup.com">SQL Solutions Group</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p><em>“Is anyone still using this database?”</em> I have been asked this question a surprising number of times lately. The answer can be trickier to find than you would think, because, by default, SQL Server doesn’t keep track. But there is a way to find stagnant databases.</p>
<p><img fetchpriority="high" decoding="async" class="alignnone wp-image-8139" src="https://sqlsolutionsgroup.com/wp-content/uploads/2026/07/worth-a-shot-.png" alt="By default, SQL Server doesn’t keep track of them, but there is a process you can follow to find stagnant databases in your environment." width="280" height="229" /></p>
<p><em>Worth a shot.</em></p>
<h3>Getting the latest user activity from a DMV</h3>
<p>If you have configured monitoring, auditing, or extended events to capture this information, then you’ve lucked out. Otherwise, your easiest option is to go looking in <strong>sys.dm_db_index_usage_stats</strong>. This is a DMV that retains information about index operations, such as the last time a user seek was performed. Just keep in mind that most DMVs reset after SQL Server is restarted.</p>
<p><strong>sys.dm_db_index_usage_stats </strong>on its own has all the information we need to check for user activity, but will only contain records for databases that have had activity since the last SQL Server restart. Since the point is to find databases with no recent activity, you will want to bring in <strong>sys.databases</strong> as well.</p>
<div id="wpshdo_1" class="wp-synhighlighter-outer"><div id="wpshdt_1" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_1"></a><a id="wpshat_1" class="wp-synhighlighter-title" href="#codesyntax_1"  onClick="javascript:wpsh_toggleBlock(1)" title="Click to show/hide code block">Source code</a></td><td align="right"><a href="#codesyntax_1" onClick="javascript:wpsh_code(1)" title="Show code only"><img decoding="async" border="0" style="border: 0 none" src="https://sqlsolutionsgroup.com/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_1" onClick="javascript:wpsh_print(1)" title="Print code"><img decoding="async" border="0" style="border: 0 none" src="https://sqlsolutionsgroup.com/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="https://sqlsolutionsgroup.com/wp-content/plugins/wp-synhighlight/About.html" target="_blank" title="Show plugin information"><img decoding="async" border="0" style="border: 0 none" src="https://sqlsolutionsgroup.com/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_1" class="wp-synhighlighter-inner" style="display: block;"><pre class="tsql" style="font-family:monospace;"><span class="kw1">SELECT</span> d.<span class="me1">name</span>
&nbsp;
,<span class="kw2">MAX</span><span class="br0">&#40;</span>i.<span class="me1">last_user_lookup</span><span class="br0">&#41;</span> last_user_lookup
&nbsp;
,<span class="kw2">MAX</span><span class="br0">&#40;</span>i.<span class="me1">last_user_scan</span><span class="br0">&#41;</span> last_user_scan
&nbsp;
,<span class="kw2">MAX</span><span class="br0">&#40;</span>i.<span class="me1">last_user_seek</span><span class="br0">&#41;</span> last_user_seek
&nbsp;
,<span class="kw2">MAX</span><span class="br0">&#40;</span>i.<span class="me1">last_user_update</span><span class="br0">&#41;</span> last_user_update
&nbsp;
<span class="kw1">FROM</span> sys.<span class="me1">databases</span> d <span class="kw1">LEFT</span> join sys.<span class="me1">dm_db_index_usage_stats</span> i <span class="kw1">ON</span> d.<span class="me1">database_id</span> <span class="sy0">=</span> i.<span class="me1">database_id</span>
&nbsp;
<span class="kw1">WHERE</span> d.<span class="me1">database_id</span> <span class="sy0">&gt;</span> 4
&nbsp;
<span class="kw1">GROUP</span> <span class="kw1">BY</span> d.<span class="me1">name</span></pre></div></div>
<p>&nbsp;</p>
<p><img decoding="async" width="811" height="273" class="wp-image-8140" src="https://sqlsolutionsgroup.com/wp-content/uploads/2026/07/a-screenshot-of-a-computer-program-ai-generated-c.png" alt="A screenshot of a computer program AI-generated content may be incorrect." srcset="https://sqlsolutionsgroup.com/wp-content/uploads/2026/07/a-screenshot-of-a-computer-program-ai-generated-c.png 811w, https://sqlsolutionsgroup.com/wp-content/uploads/2026/07/a-screenshot-of-a-computer-program-ai-generated-c-300x101.png 300w, https://sqlsolutionsgroup.com/wp-content/uploads/2026/07/a-screenshot-of-a-computer-program-ai-generated-c-768x259.png 768w" sizes="(max-width: 811px) 100vw, 811px" /></p>
<p>None of my user databases have had any user activity since the SQL Server service was last restarted, so let’s generate some activity.</p>
<p><img decoding="async" width="386" height="136" class="wp-image-8141" src="https://sqlsolutionsgroup.com/wp-content/uploads/2026/07/a-screenshot-of-a-computer-ai-generated-content-m.png" alt="A screenshot of a computer AI-generated content may be incorrect." srcset="https://sqlsolutionsgroup.com/wp-content/uploads/2026/07/a-screenshot-of-a-computer-ai-generated-content-m.png 386w, https://sqlsolutionsgroup.com/wp-content/uploads/2026/07/a-screenshot-of-a-computer-ai-generated-content-m-300x106.png 300w" sizes="(max-width: 386px) 100vw, 386px" /></p>
<p>Now let’s check the DMV again.</p>
<p><img loading="lazy" decoding="async" width="814" height="275" class="wp-image-8142" src="https://sqlsolutionsgroup.com/wp-content/uploads/2026/07/a-screenshot-of-a-computer-program-ai-generated-c-1.png" alt="A screenshot of a computer program AI-generated content may be incorrect." srcset="https://sqlsolutionsgroup.com/wp-content/uploads/2026/07/a-screenshot-of-a-computer-program-ai-generated-c-1.png 814w, https://sqlsolutionsgroup.com/wp-content/uploads/2026/07/a-screenshot-of-a-computer-program-ai-generated-c-1-300x101.png 300w, https://sqlsolutionsgroup.com/wp-content/uploads/2026/07/a-screenshot-of-a-computer-program-ai-generated-c-1-768x259.png 768w" sizes="(max-width: 814px) 100vw, 814px" /></p>
<p>There is our proof that the StackOverflowDW database is at least being queried, so we will want to do some more investigation to find out who or what is accessing the database.</p>
<h3>A More Resilient Method</h3>
<p>If it has been weeks or months since the SQL Server service has been restarted, then this would be a good indication that the StackOverflowMini and DBA databases are stagnant, while StackOverflowDW is active. But what if your servers are regularly restarted, planned or otherwise? Then you should set up a more resilient method for tracking this info.</p>
<p>If you are content with this data, it is easy enough to set up a SQL Agent job to persist it to a table. It is an easy-to-read dataset that is scoped to the server level, so you don’t need to query each individual database.</p>
<p>First, create the table. I am just going to use the master database.</p>
<div id="wpshdo_2" class="wp-synhighlighter-outer"><div id="wpshdt_2" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_2"></a><a id="wpshat_2" class="wp-synhighlighter-title" href="#codesyntax_2"  onClick="javascript:wpsh_toggleBlock(2)" title="Click to show/hide code block">Source code</a></td><td align="right"><a href="#codesyntax_2" onClick="javascript:wpsh_code(2)" title="Show code only"><img decoding="async" border="0" style="border: 0 none" src="https://sqlsolutionsgroup.com/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_2" onClick="javascript:wpsh_print(2)" title="Print code"><img decoding="async" border="0" style="border: 0 none" src="https://sqlsolutionsgroup.com/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="https://sqlsolutionsgroup.com/wp-content/plugins/wp-synhighlight/About.html" target="_blank" title="Show plugin information"><img decoding="async" border="0" style="border: 0 none" src="https://sqlsolutionsgroup.com/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_2" class="wp-synhighlighter-inner" style="display: block;"><pre class="tsql" style="font-family:monospace;"><span class="kw1">USE</span> master
&nbsp;
<span class="kw1">CREATE</span> <span class="kw1">TABLE</span> LastUserActivity
&nbsp;
<span class="br0">&#40;</span>
&nbsp;
database_name <span class="kw1">NVARCHAR</span><span class="br0">&#40;</span>100<span class="br0">&#41;</span>
&nbsp;
,last_user_lookup <span class="kw1">DATETIME</span> null
&nbsp;
,last_user_scan <span class="kw1">DATETIME</span> null
&nbsp;
,last_user_seek <span class="kw1">DATETIME</span> null
&nbsp;
,last_user_update <span class="kw1">DATETIME</span> null
&nbsp;
,insert_date <span class="kw1">DATETIME</span> <span class="kw1">DEFAULT</span> <span class="kw2">GETDATE</span><span class="br0">&#40;</span><span class="br0">&#41;</span>
&nbsp;
<span class="br0">&#41;</span></pre></div></div>
<p>&nbsp;</p>
<p>Then create a SQL Agent job to execute the query and load the results to your new LastUserActivity table. Make sure to add a cleanup step so the table size doesn’t get out of control.</p>
<p>&nbsp;</p>
<div id="wpshdo_3" class="wp-synhighlighter-outer"><div id="wpshdt_3" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_3"></a><a id="wpshat_3" class="wp-synhighlighter-title" href="#codesyntax_3"  onClick="javascript:wpsh_toggleBlock(3)" title="Click to show/hide code block">Source code</a></td><td align="right"><a href="#codesyntax_3" onClick="javascript:wpsh_code(3)" title="Show code only"><img decoding="async" border="0" style="border: 0 none" src="https://sqlsolutionsgroup.com/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_3" onClick="javascript:wpsh_print(3)" title="Print code"><img decoding="async" border="0" style="border: 0 none" src="https://sqlsolutionsgroup.com/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="https://sqlsolutionsgroup.com/wp-content/plugins/wp-synhighlight/About.html" target="_blank" title="Show plugin information"><img decoding="async" border="0" style="border: 0 none" src="https://sqlsolutionsgroup.com/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_3" class="wp-synhighlighter-inner" style="display: block;"><pre class="tsql" style="font-family:monospace;"><span class="kw1">INSERT</span> <span class="kw1">INTO</span> LastUserActivity
&nbsp;
<span class="br0">&#40;</span>
&nbsp;
database_name
&nbsp;
,last_user_lookup
&nbsp;
,last_user_scan
&nbsp;
,last_user_seek
&nbsp;
,last_user_update
&nbsp;
<span class="br0">&#41;</span>
&nbsp;
<span class="kw1">SELECT</span> d.<span class="me1">name</span>
&nbsp;
,<span class="kw2">MAX</span><span class="br0">&#40;</span>i.<span class="me1">last_user_lookup</span><span class="br0">&#41;</span> last_user_lookup
&nbsp;
,<span class="kw2">MAX</span><span class="br0">&#40;</span>i.<span class="me1">last_user_scan</span><span class="br0">&#41;</span> last_user_scan
&nbsp;
,<span class="kw2">MAX</span><span class="br0">&#40;</span>i.<span class="me1">last_user_seek</span><span class="br0">&#41;</span> last_user_seek
&nbsp;
,<span class="kw2">MAX</span><span class="br0">&#40;</span>i.<span class="me1">last_user_update</span><span class="br0">&#41;</span> last_user_update
&nbsp;
<span class="kw1">FROM</span> sys.<span class="me1">databases</span> d <span class="kw1">LEFT</span> join sys.<span class="me1">dm_db_index_usage_stats</span> i <span class="kw1">ON</span> d.<span class="me1">database_id</span> <span class="sy0">=</span> i.<span class="me1">database_id</span>
&nbsp;
<span class="kw1">WHERE</span> d.<span class="me1">database_id</span> <span class="sy0">&gt;</span> 4
&nbsp;
<span class="kw1">GROUP</span> <span class="kw1">BY</span> d.<span class="me1">name</span></pre></div></div>
<p>&nbsp;</p>
<p><img loading="lazy" decoding="async" class="alignnone wp-image-8143" src="https://sqlsolutionsgroup.com/wp-content/uploads/2026/07/word-image-8138-5.png" alt="By default, SQL Server doesn’t keep track of them, but there is a process you can follow to find stagnant databases in your environment." width="704" height="655" srcset="https://sqlsolutionsgroup.com/wp-content/uploads/2026/07/word-image-8138-5.png 704w, https://sqlsolutionsgroup.com/wp-content/uploads/2026/07/word-image-8138-5-300x279.png 300w" sizes="(max-width: 704px) 100vw, 704px" /></p>
<p><img loading="lazy" decoding="async" width="700" height="652" class="wp-image-8144" src="https://sqlsolutionsgroup.com/wp-content/uploads/2026/07/a-screenshot-of-a-computer-ai-generated-content-m-1.png" alt="A screenshot of a computer AI-generated content may be incorrect." srcset="https://sqlsolutionsgroup.com/wp-content/uploads/2026/07/a-screenshot-of-a-computer-ai-generated-content-m-1.png 700w, https://sqlsolutionsgroup.com/wp-content/uploads/2026/07/a-screenshot-of-a-computer-ai-generated-content-m-1-300x279.png 300w" sizes="(max-width: 700px) 100vw, 700px" /></p>
<p>Schedule the job to run as frequently as you would like. Running daily should be more than sufficient.</p>
<p>&nbsp;</p>
<div id="wpshdo_4" class="wp-synhighlighter-outer"><div id="wpshdt_4" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_4"></a><a id="wpshat_4" class="wp-synhighlighter-title" href="#codesyntax_4"  onClick="javascript:wpsh_toggleBlock(4)" title="Click to show/hide code block">Source code</a></td><td align="right"><a href="#codesyntax_4" onClick="javascript:wpsh_code(4)" title="Show code only"><img decoding="async" border="0" style="border: 0 none" src="https://sqlsolutionsgroup.com/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_4" onClick="javascript:wpsh_print(4)" title="Print code"><img decoding="async" border="0" style="border: 0 none" src="https://sqlsolutionsgroup.com/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="https://sqlsolutionsgroup.com/wp-content/plugins/wp-synhighlight/About.html" target="_blank" title="Show plugin information"><img decoding="async" border="0" style="border: 0 none" src="https://sqlsolutionsgroup.com/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_4" class="wp-synhighlighter-inner" style="display: block;"><pre class="tsql" style="font-family:monospace;"><span class="kw1">SELECT</span> database_name
&nbsp;
,last_user_lookup
&nbsp;
,last_user_scan
&nbsp;
,last_user_seek
&nbsp;
,last_user_update
&nbsp;
,insert_date
&nbsp;
<span class="kw1">FROM</span> master.<span class="me1">dbo</span>.<span class="me1">LastUserActivity</span></pre></div></div>
<p><img loading="lazy" decoding="async" width="693" height="254" class="wp-image-8145" src="https://sqlsolutionsgroup.com/wp-content/uploads/2026/07/a-screenshot-of-a-computer-ai-generated-content-m-2.png" alt="A screenshot of a computer AI-generated content may be incorrect." srcset="https://sqlsolutionsgroup.com/wp-content/uploads/2026/07/a-screenshot-of-a-computer-ai-generated-content-m-2.png 693w, https://sqlsolutionsgroup.com/wp-content/uploads/2026/07/a-screenshot-of-a-computer-ai-generated-content-m-2-300x110.png 300w" sizes="(max-width: 693px) 100vw, 693px" /></p>
<h3>You&#8217;ve Done It</h3>
<p>Now you will always have a small dataset with the latest activity for each database, making it much easier to find stagnant databases.</p>
<p>&nbsp;</p>
<p>The post <a href="https://sqlsolutionsgroup.com/finding-stagnant-databases/">&#8220;Is anyone still using this database?&#8221; How to find stagnant databases</a> appeared first on <a href="https://sqlsolutionsgroup.com">SQL Solutions Group</a>.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Why use PowerShell when you can use T-SQL?</title>
		<link>https://sqlsolutionsgroup.com/why-use-powershell/</link>
					<comments>https://sqlsolutionsgroup.com/why-use-powershell/#comments</comments>
		
		<dc:creator><![CDATA[Kyle Burwell]]></dc:creator>
		<pubDate>Wed, 11 Mar 2026 20:27:28 +0000</pubDate>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[#microsftcertifedmaster #microsftpartner]]></category>
		<category><![CDATA[#sqldatabase]]></category>
		<category><![CDATA[#sqldeveloper]]></category>
		<category><![CDATA[#SQLLearning]]></category>
		<category><![CDATA[#sqlserver]]></category>
		<category><![CDATA[#SQLsolutionsgroup]]></category>
		<category><![CDATA[#SQLTraining]]></category>
		<guid isPermaLink="false">https://sqlgroupstg.wpengine.com/?p=7450</guid>

					<description><![CDATA[<p>Why use PowerShell? I’ve lost count of how many times I have been asked this question. Most of the time, the inquirer is asking out of genuine curiosity. Other times, there is some obvious (negative) judgement in the question. Either way, my answer is the same: “It’s easier.” I will go through a couple of [&#8230;]</p>
<p>The post <a href="https://sqlsolutionsgroup.com/why-use-powershell/">Why use PowerShell when you can use T-SQL?</a> appeared first on <a href="https://sqlsolutionsgroup.com">SQL Solutions Group</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p><em><strong><span style="color: #f25e00;">Why use PowerShell?</span></strong></em> I’ve lost count of how many times I have been asked this question. Most of the time, the inquirer is asking out of genuine curiosity. Other times, there is some obvious (negative) judgement in the question. Either way, my answer is the same: “<span style="color: #f25e00;"><strong>It’s easier</strong></span>.”</p>
<p>I will go through a couple of common scenarios that we frequently encounter and give T-SQL and PowerShell solutions.</p>
<h3>Is Max Memory Set Appropriately?</h3>
<p>Let’s start small: Finding max memory values and evaluating if they are appropriate.</p>
<p><strong>T-SQL Script:</strong></p>
<div id="wpshdo_5" class="wp-synhighlighter-outer"><div id="wpshdt_5" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_5"></a><a id="wpshat_5" class="wp-synhighlighter-title" href="#codesyntax_5"  onClick="javascript:wpsh_toggleBlock(5)" title="Click to show/hide code block">Source code</a></td><td align="right"><a href="#codesyntax_5" onClick="javascript:wpsh_code(5)" title="Show code only"><img decoding="async" border="0" style="border: 0 none" src="https://sqlsolutionsgroup.com/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_5" onClick="javascript:wpsh_print(5)" title="Print code"><img decoding="async" border="0" style="border: 0 none" src="https://sqlsolutionsgroup.com/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="https://sqlsolutionsgroup.com/wp-content/plugins/wp-synhighlight/About.html" target="_blank" title="Show plugin information"><img decoding="async" border="0" style="border: 0 none" src="https://sqlsolutionsgroup.com/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_5" class="wp-synhighlighter-inner" style="display: block;"><pre class="tsql" style="font-family:monospace;"><span class="kw1">SELECT</span> mem.<span class="me1">total_physical_memory_kb</span> <span class="sy0">/</span> <span class="nu0">1024</span> <span class="st0">'server memory (MB)'</span>
&nbsp;
,configs.<span class="me1">value_in_use</span> <span class="st0">'max server memory (MB)'</span>
&nbsp;
<span class="kw1">FROM</span> sys.<span class="me1">dm_os_sys_memory</span> mem
&nbsp;
cross apply <span class="br0">&#40;</span>
&nbsp;
<span class="kw1">SELECT</span> value_in_use
&nbsp;
<span class="kw1">FROM</span> sys.<span class="me1">configurations</span>
&nbsp;
<span class="kw1">WHERE</span> name <span class="sy0">=</span> <span class="st0">'max server memory (MB)'</span>
&nbsp;
<span class="br0">&#41;</span> configs</pre></div></div>
<p><strong>T-SQL Results:</strong><br />
<img loading="lazy" decoding="async" width="277" height="46" class="wp-image-7451" src="https://sqlsolutionsgroup.com/wp-content/uploads/2026/03/word-image-7450-1.png" /></p>
<p>With that information, I can make a determination if Max Memory is set appropriately. If not, I can calculate an appropriate value and go implement the change.</p>
<p><strong>PowerShell Script:</strong></p>
<div id="wpshdo_6" class="wp-synhighlighter-outer"><div id="wpshdt_6" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_6"></a><a id="wpshat_6" class="wp-synhighlighter-title" href="#codesyntax_6"  onClick="javascript:wpsh_toggleBlock(6)" title="Click to show/hide code block">Source code</a></td><td align="right"><a href="#codesyntax_6" onClick="javascript:wpsh_code(6)" title="Show code only"><img decoding="async" border="0" style="border: 0 none" src="https://sqlsolutionsgroup.com/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_6" onClick="javascript:wpsh_print(6)" title="Print code"><img decoding="async" border="0" style="border: 0 none" src="https://sqlsolutionsgroup.com/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="https://sqlsolutionsgroup.com/wp-content/plugins/wp-synhighlight/About.html" target="_blank" title="Show plugin information"><img decoding="async" border="0" style="border: 0 none" src="https://sqlsolutionsgroup.com/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_6" class="wp-synhighlighter-inner" style="display: block;"><pre class="powershell" style="font-family:monospace;">Test<span class="sy0">-</span>DbaMaxMemory <span class="sy0">-</span>SqlInstance SSG<span class="kw4">-LT</span><span class="sy0">-</span>KBURWELL</pre></div></div>
<p><strong>PowerShell Results:<br />
<img loading="lazy" decoding="async" width="250" height="130" class="wp-image-7452" src="https://sqlsolutionsgroup.com/wp-content/uploads/2026/03/a-screenshot-of-a-computer-screen-ai-generated-co.png" alt="A screenshot of a computer screen AI-generated content may be incorrect." /></strong></p>
<p>Again, this is a basic example, and the T-SQL isn’t exactly complex, but the PowerShell is much easier and even gives you a recommendation for Max Memory.</p>
<h3>LastFullBackup</h3>
<p>The T-SQL for this is also rather easy, but the tricky part is running it against multiple instances and returning a single result set.</p>
<p><strong>T-SQL Script:</strong></p>
<div id="wpshdo_7" class="wp-synhighlighter-outer"><div id="wpshdt_7" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_7"></a><a id="wpshat_7" class="wp-synhighlighter-title" href="#codesyntax_7"  onClick="javascript:wpsh_toggleBlock(7)" title="Click to show/hide code block">Source code</a></td><td align="right"><a href="#codesyntax_7" onClick="javascript:wpsh_code(7)" title="Show code only"><img decoding="async" border="0" style="border: 0 none" src="https://sqlsolutionsgroup.com/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_7" onClick="javascript:wpsh_print(7)" title="Print code"><img decoding="async" border="0" style="border: 0 none" src="https://sqlsolutionsgroup.com/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="https://sqlsolutionsgroup.com/wp-content/plugins/wp-synhighlight/About.html" target="_blank" title="Show plugin information"><img decoding="async" border="0" style="border: 0 none" src="https://sqlsolutionsgroup.com/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_7" class="wp-synhighlighter-inner" style="display: block;"><pre class="tsql" style="font-family:monospace;"><span class="kw1">SELECT</span> database_name
&nbsp;
,<span class="kw2">MAX</span><span class="br0">&#40;</span>backup_start_date<span class="br0">&#41;</span> latest_full
&nbsp;
<span class="kw1">FROM</span> msdb.<span class="me1">dbo</span>.<span class="me1">backupset</span> s
&nbsp;
<span class="kw1">WHERE</span> s.<span class="me1">type</span> <span class="sy0">=</span> <span class="st0">'D'</span>
&nbsp;
<span class="kw1">GROUP</span> <span class="kw1">BY</span> s.<span class="me1">database_name</span></pre></div></div>
<p><strong>T-SQL Results:</strong></p>
<p><strong><img loading="lazy" decoding="async" width="352" height="110" class="wp-image-7453" src="https://sqlsolutionsgroup.com/wp-content/uploads/2026/03/a-screenshot-of-a-computer-ai-generated-content-m.png" alt="A screenshot of a computer AI-generated content may be incorrect." srcset="https://sqlsolutionsgroup.com/wp-content/uploads/2026/03/a-screenshot-of-a-computer-ai-generated-content-m.png 352w, https://sqlsolutionsgroup.com/wp-content/uploads/2026/03/a-screenshot-of-a-computer-ai-generated-content-m-300x94.png 300w" sizes="(max-width: 352px) 100vw, 352px" /></strong></p>
<p>As I mentioned, this is a very simple script, but this is <span style="color: #f25e00;"><strong>only for one instance</strong></span>. If you want to run this against multiple instances, you will need to do some additional setup, such as configuring linked servers or a Central Management Server, neither of which I will be detailing here. Instead, I will show how easy it is to query multiple instances in PowerShell.</p>
<p><strong>PowerShell Script:</strong></p>
<div id="wpshdo_8" class="wp-synhighlighter-outer"><div id="wpshdt_8" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_8"></a><a id="wpshat_8" class="wp-synhighlighter-title" href="#codesyntax_8"  onClick="javascript:wpsh_toggleBlock(8)" title="Click to show/hide code block">Source code</a></td><td align="right"><a href="#codesyntax_8" onClick="javascript:wpsh_code(8)" title="Show code only"><img decoding="async" border="0" style="border: 0 none" src="https://sqlsolutionsgroup.com/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_8" onClick="javascript:wpsh_print(8)" title="Print code"><img decoding="async" border="0" style="border: 0 none" src="https://sqlsolutionsgroup.com/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="https://sqlsolutionsgroup.com/wp-content/plugins/wp-synhighlight/About.html" target="_blank" title="Show plugin information"><img decoding="async" border="0" style="border: 0 none" src="https://sqlsolutionsgroup.com/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_8" class="wp-synhighlighter-inner" style="display: block;"><pre class="powershell" style="font-family:monospace;">Get<span class="sy0">-</span>DbaLastBackup <span class="sy0">-</span>SqlInstance SSG<span class="kw4">-LT</span><span class="sy0">-</span>KBURWELL</pre></div></div>
<p><strong>PowerShell Results:<br />
<img loading="lazy" decoding="async" width="377" height="555" class="wp-image-7454" src="https://sqlsolutionsgroup.com/wp-content/uploads/2026/03/word-image-7450-4.png" srcset="https://sqlsolutionsgroup.com/wp-content/uploads/2026/03/word-image-7450-4.png 377w, https://sqlsolutionsgroup.com/wp-content/uploads/2026/03/word-image-7450-4-204x300.png 204w" sizes="(max-width: 377px) 100vw, 377px" /></strong></p>
<p>One simple command and I get the same info, plus details for latest diff and log backups as well. Now let’s make a couple of changes so we can get results for multiple instances and make the output a little more friendly.</p>
<p><strong>PowerShell Script:</strong></p>
<div id="wpshdo_9" class="wp-synhighlighter-outer"><div id="wpshdt_9" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_9"></a><a id="wpshat_9" class="wp-synhighlighter-title" href="#codesyntax_9"  onClick="javascript:wpsh_toggleBlock(9)" title="Click to show/hide code block">Source code</a></td><td align="right"><a href="#codesyntax_9" onClick="javascript:wpsh_code(9)" title="Show code only"><img decoding="async" border="0" style="border: 0 none" src="https://sqlsolutionsgroup.com/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_9" onClick="javascript:wpsh_print(9)" title="Print code"><img decoding="async" border="0" style="border: 0 none" src="https://sqlsolutionsgroup.com/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="https://sqlsolutionsgroup.com/wp-content/plugins/wp-synhighlight/About.html" target="_blank" title="Show plugin information"><img decoding="async" border="0" style="border: 0 none" src="https://sqlsolutionsgroup.com/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_9" class="wp-synhighlighter-inner" style="display: block;"><pre class="powershell" style="font-family:monospace;">Get<span class="sy0">-</span>DbaLastBackup <span class="sy0">-</span>SqlInstance SSG<span class="kw4">-LT</span><span class="sy0">-</span>KBURWELL<span class="sy0">,</span>SSG<span class="kw4">-LT</span><span class="sy0">-</span>KBURWELL\MSSQLSERVER01 <span class="sy0">-</span>ExcludeDatabase msdb<span class="sy0">,</span>model<span class="sy0">,</span>master <span class="sy0">|</span> <span class="kw1">Format-Table</span></pre></div></div>
<p>I made 3 minor changes to the script, but it is still a single line of code and now reads from multiple instances and formats the output as a table.</p>
<ul>
<li><span style="color: #f25e00;"><strong>Change 1</strong></span>: Added an additional SQL instance to the -SqlInstance parameter.</li>
<li><span style="color: #f25e00;"><strong>Change 2</strong></span>: Added the -ExcludeDatabase parameter and passed in the system databases.</li>
<li><span style="color: #f25e00;"><strong>Change 3</strong></span>: Piped the results to Format-Table</li>
</ul>
<p><strong>PowerShell Results:</strong></p>
<p><strong><img loading="lazy" decoding="async" width="1185" height="182" class="wp-image-7455" src="https://sqlsolutionsgroup.com/wp-content/uploads/2026/03/word-image-7450-5.png" srcset="https://sqlsolutionsgroup.com/wp-content/uploads/2026/03/word-image-7450-5.png 1185w, https://sqlsolutionsgroup.com/wp-content/uploads/2026/03/word-image-7450-5-300x46.png 300w, https://sqlsolutionsgroup.com/wp-content/uploads/2026/03/word-image-7450-5-1024x157.png 1024w, https://sqlsolutionsgroup.com/wp-content/uploads/2026/03/word-image-7450-5-768x118.png 768w" sizes="(max-width: 1185px) 100vw, 1185px" /></strong></p>
<p>Let’s take it one step further and generate a spreadsheet from the results.</p>
<p><strong>PowerShell Script:</strong></p>
<div id="wpshdo_10" class="wp-synhighlighter-outer"><div id="wpshdt_10" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_10"></a><a id="wpshat_10" class="wp-synhighlighter-title" href="#codesyntax_10"  onClick="javascript:wpsh_toggleBlock(10)" title="Click to show/hide code block">Source code</a></td><td align="right"><a href="#codesyntax_10" onClick="javascript:wpsh_code(10)" title="Show code only"><img decoding="async" border="0" style="border: 0 none" src="https://sqlsolutionsgroup.com/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_10" onClick="javascript:wpsh_print(10)" title="Print code"><img decoding="async" border="0" style="border: 0 none" src="https://sqlsolutionsgroup.com/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="https://sqlsolutionsgroup.com/wp-content/plugins/wp-synhighlight/About.html" target="_blank" title="Show plugin information"><img decoding="async" border="0" style="border: 0 none" src="https://sqlsolutionsgroup.com/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_10" class="wp-synhighlighter-inner" style="display: block;"><pre class="powershell" style="font-family:monospace;">Get<span class="sy0">-</span>DbaLastBackup <span class="sy0">-</span>SqlInstance SSG<span class="kw4">-LT</span><span class="sy0">-</span>KBURWELL<span class="sy0">,</span>SSG<span class="kw4">-LT</span><span class="sy0">-</span>KBURWELL\MSSQLSERVER01 <span class="sy0">-</span>ExcludeDatabase msdb<span class="sy0">,</span>model<span class="sy0">,</span>master <span class="sy0">|</span> Export<span class="sy0">-</span>Excel <span class="kw5">-Path</span> C:\Temp\LastBackups.xlsx</pre></div></div>
<p>Instead of piping the results to Format-Table, I am piping the results to Export-Excel and providing a file path and name. Now I have a spreadsheet that I can share with whomever might want to see it.</p>
<p><img loading="lazy" decoding="async" width="327" height="153" class="wp-image-7456" src="https://sqlsolutionsgroup.com/wp-content/uploads/2026/03/a-screenshot-of-a-computer-ai-generated-content-m-1.png" alt="A screenshot of a computer AI-generated content may be incorrect." srcset="https://sqlsolutionsgroup.com/wp-content/uploads/2026/03/a-screenshot-of-a-computer-ai-generated-content-m-1.png 327w, https://sqlsolutionsgroup.com/wp-content/uploads/2026/03/a-screenshot-of-a-computer-ai-generated-content-m-1-300x140.png 300w" sizes="(max-width: 327px) 100vw, 327px" /></p>
<p>Getting results from SSMS into Excel is obviously possible, it just requires extra manual steps. It&#8217;s much quicker to just have PowerShell do it for you.</p>
<h3>“It’s easier”</h3>
<p>When I say PowerShell is easier, I’m not just talking about the simplicity of commands. I’m also talking about how easy it is to add in functionality, such as querying multiple instances, combining the results, and exporting them to Excel.</p>
<p>If you are perfectly happy using T-SQL and SSMS, then by all means, continue to do so. <em><strong>But</strong></em>, I do encourage you to explore PowerShell, specifically the <a href="dbatools.io">DBATools</a> module. I will be following up this post with more complex Powershell examples such as copying databases between SQL instances and keeping AG objects synchronized between replicas. Stay tuned for more answers to the question &#8220;why use PowerShell?&#8221;</p>
<p>&nbsp;</p>
<p>The post <a href="https://sqlsolutionsgroup.com/why-use-powershell/">Why use PowerShell when you can use T-SQL?</a> appeared first on <a href="https://sqlsolutionsgroup.com">SQL Solutions Group</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://sqlsolutionsgroup.com/why-use-powershell/feed/</wfw:commentRss>
			<slash:comments>2</slash:comments>
		
		
			</item>
		<item>
		<title>Track Database File Sizes with PowerShell: A Quick Guide for DBAs</title>
		<link>https://sqlsolutionsgroup.com/track-database-file-sizes-with-powershell/</link>
					<comments>https://sqlsolutionsgroup.com/track-database-file-sizes-with-powershell/#comments</comments>
		
		<dc:creator><![CDATA[Kyle Burwell]]></dc:creator>
		<pubDate>Mon, 29 Dec 2025 10:48:30 +0000</pubDate>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[#PowerShell]]></category>
		<category><![CDATA[#sqlserver]]></category>
		<category><![CDATA[DBA]]></category>
		<guid isPermaLink="false">https://sqlsolutionsgroup.com/?p=7348</guid>

					<description><![CDATA[<p>Database files (mdf, nds, ldfs, etc.) can get out of hand quickly and easily, leading to issues down the road. This can be due to improper planning, large data loads, and bad code run in production, just to list a few. As unglamorous as disk space monitoring is, we need to do our part as [&#8230;]</p>
<p>The post <a href="https://sqlsolutionsgroup.com/track-database-file-sizes-with-powershell/">Track Database File Sizes with PowerShell: A Quick Guide for DBAs</a> appeared first on <a href="https://sqlsolutionsgroup.com">SQL Solutions Group</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>Database files (mdf, nds, ldfs, etc.) can get out of hand quickly and easily, leading to issues down the road. This can be due to improper planning, large data loads, and bad code run in production, just to list a few. As unglamorous as disk space monitoring is, we need to do our part as DBAs. This post is a quick guide on how to track database file sizes with PowerShell.</p>
<h3>Getting Started</h3>
<p>If you haven’t already, make sure you have <a href="https://dbatools.io/">DBATools</a> installed. We are going to be using a command called <strong>Get-DbaDbFile</strong> to gather the information for us. This command only requires one parameter, <strong>-SqlInstance</strong>. Here is a snippet of what I get when I run it against my local dev instance:</p>
<figure id="attachment_7349" aria-describedby="caption-attachment-7349" style="width: 757px" class="wp-caption alignnone"><img loading="lazy" decoding="async" class="wp-image-7349" src="https://sqlsolutionsgroup.com/wp-content/uploads/2025/12/a-screenshot-of-a-computer-ai-generated-content-m.png" alt="A screenshot of a computerAI-generated content may be incorrect." width="757" height="632" srcset="https://sqlsolutionsgroup.com/wp-content/uploads/2025/12/a-screenshot-of-a-computer-ai-generated-content-m.png 757w, https://sqlsolutionsgroup.com/wp-content/uploads/2025/12/a-screenshot-of-a-computer-ai-generated-content-m-300x250.png 300w" sizes="(max-width: 757px) 100vw, 757px" /><figcaption id="caption-attachment-7349" class="wp-caption-text">Figure 1: Really Kyle? Data files on the C: drive?</figcaption></figure>
<p>&nbsp;</p>
<p>This is a bit more information than we really need right now, so let’s trim it down and get some parameters added. For this script, we really only need SqlInstance, Database, TypeDescription, LogicalName, PhysicalName, Size, UsedSpace, and AvailableSpace. We can also exclude system databases from the result set. For readability, I am going to use Format-Table. I will also start to add in some parameters:</p>
<div id="wpshdo_11" class="wp-synhighlighter-outer"><div id="wpshdt_11" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_11"></a><a id="wpshat_11" class="wp-synhighlighter-title" href="#codesyntax_11"  onClick="javascript:wpsh_toggleBlock(11)" title="Click to show/hide code block">Source code</a></td><td align="right"><a href="#codesyntax_11" onClick="javascript:wpsh_code(11)" title="Show code only"><img decoding="async" border="0" style="border: 0 none" src="https://sqlsolutionsgroup.com/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_11" onClick="javascript:wpsh_print(11)" title="Print code"><img decoding="async" border="0" style="border: 0 none" src="https://sqlsolutionsgroup.com/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="https://sqlsolutionsgroup.com/wp-content/plugins/wp-synhighlight/About.html" target="_blank" title="Show plugin information"><img decoding="async" border="0" style="border: 0 none" src="https://sqlsolutionsgroup.com/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_11" class="wp-synhighlighter-inner" style="display: block;"><pre class="powershell" style="font-family:monospace;"><span class="re0">$SqlInstance</span> <span class="sy0">=</span> <span class="st0">&quot;SSG-LT-KBURWELL&quot;</span>
&nbsp;
Get<span class="sy0">-</span>DbaDbFile <span class="sy0">-</span>SqlInstance <span class="re0">$SqlInstance</span>
&nbsp;
Get<span class="sy0">-</span>DbaDbFile <span class="sy0">-</span>SqlInstance <span class="re0">$SqlInstance</span> <span class="sy0">-</span>ExcludeDatabase master<span class="sy0">,</span>model<span class="sy0">,</span>msdb<span class="sy0">,</span>tempdb <span class="sy0">|</span>
&nbsp;
    <span class="kw1">Select-Object</span> SqlInstance<span class="sy0">,</span> Database<span class="sy0">,</span> TypeDescription<span class="sy0">,</span> LogicalName<span class="sy0">,</span> PhysicalName<span class="sy0">,</span> Size<span class="sy0">,</span> UsedSpace<span class="sy0">,</span> AvailableSpace <span class="sy0">|</span> <span class="kw1">Format-Table</span></pre></div></div>
<p><img loading="lazy" decoding="async" class="alignnone wp-image-7350" src="https://sqlsolutionsgroup.com/wp-content/uploads/2025/12/word-image-7348-2.png" alt="track database file sizes with Powershell" width="1410" height="138" srcset="https://sqlsolutionsgroup.com/wp-content/uploads/2025/12/word-image-7348-2.png 1410w, https://sqlsolutionsgroup.com/wp-content/uploads/2025/12/word-image-7348-2-300x29.png 300w, https://sqlsolutionsgroup.com/wp-content/uploads/2025/12/word-image-7348-2-1024x100.png 1024w, https://sqlsolutionsgroup.com/wp-content/uploads/2025/12/word-image-7348-2-768x75.png 768w" sizes="(max-width: 1410px) 100vw, 1410px" /></p>
<h3>Using Custom Objects</h3>
<p>This will be much easier to work with, but it is important to be aware that the columns related to file size have GB, MB, and KB values, depending on what is most appropriate for that file size. This is great when just looking at the data like this, but can be a bit problematic for mathematical comparisons, which we will be doing later. To get around this, we can just use some custom objects:</p>
<div id="wpshdo_12" class="wp-synhighlighter-outer"><div id="wpshdt_12" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_12"></a><a id="wpshat_12" class="wp-synhighlighter-title" href="#codesyntax_12"  onClick="javascript:wpsh_toggleBlock(12)" title="Click to show/hide code block">Source code</a></td><td align="right"><a href="#codesyntax_12" onClick="javascript:wpsh_code(12)" title="Show code only"><img decoding="async" border="0" style="border: 0 none" src="https://sqlsolutionsgroup.com/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_12" onClick="javascript:wpsh_print(12)" title="Print code"><img decoding="async" border="0" style="border: 0 none" src="https://sqlsolutionsgroup.com/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="https://sqlsolutionsgroup.com/wp-content/plugins/wp-synhighlight/About.html" target="_blank" title="Show plugin information"><img decoding="async" border="0" style="border: 0 none" src="https://sqlsolutionsgroup.com/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_12" class="wp-synhighlighter-inner" style="display: block;"><pre class="powershell" style="font-family:monospace;"><span class="re0">$SqlInstance</span> <span class="sy0">=</span> <span class="st0">&quot;SSG-LT-KBURWELL&quot;</span>
&nbsp;
Get<span class="sy0">-</span>DbaDbFile <span class="sy0">-</span>SqlInstance <span class="re0">$SqlInstance</span> <span class="sy0">-</span>ExcludeDatabase master<span class="sy0">,</span>model<span class="sy0">,</span>msdb<span class="sy0">,</span>tempdb <span class="sy0">|</span>
&nbsp;
    <span class="kw1">Select-Object</span> SqlInstance<span class="sy0">,</span> TypeDescription<span class="sy0">,</span> LogicalName<span class="sy0">,</span> PhysicalName<span class="sy0">,</span>
&nbsp;
     <span class="sy0">@</span><span class="br0">&#123;</span>Name<span class="sy0">=</span><span class="st0">'DatabaseName'</span>; Expression<span class="sy0">=</span><span class="br0">&#123;</span><a href="about:blank"><span class="kw6">$_</span></a>.Database<span class="br0">&#125;</span><span class="br0">&#125;</span><span class="sy0">,</span>
&nbsp;
     <span class="sy0">@</span><span class="br0">&#123;</span>Name<span class="sy0">=</span><span class="st0">'SizeMB'</span>; Expression<span class="sy0">=</span><span class="br0">&#123;</span> <span class="br0">[</span>math<span class="br0">]</span>::Round<span class="br0">&#40;</span><a href="about:blank"><span class="kw6">$_</span></a>.Size <span class="sy0">/</span> 1MB<span class="sy0">,</span> <span class="nu0">2</span><span class="br0">&#41;</span> <span class="br0">&#125;</span><span class="br0">&#125;</span><span class="sy0">,</span>
&nbsp;
     <span class="sy0">@</span><span class="br0">&#123;</span>Name<span class="sy0">=</span><span class="st0">'UsedSpaceMB'</span>; Expression<span class="sy0">=</span><span class="br0">&#123;</span> <span class="br0">[</span>math<span class="br0">]</span>::Round<span class="br0">&#40;</span><a href="about:blank"><span class="kw6">$_</span></a>.UsedSpace <span class="sy0">/</span> 1MB<span class="sy0">,</span> <span class="nu0">2</span><span class="br0">&#41;</span> <span class="br0">&#125;</span><span class="br0">&#125;</span><span class="sy0">,</span>
&nbsp;
     <span class="sy0">@</span><span class="br0">&#123;</span>Name<span class="sy0">=</span><span class="st0">'AvailableSpaceMB'</span>; Expression<span class="sy0">=</span><span class="br0">&#123;</span> <span class="br0">[</span>math<span class="br0">]</span>::Round<span class="br0">&#40;</span><a href="about:blank"><span class="kw6">$_</span></a>.AvailableSpace <span class="sy0">/</span> 1MB<span class="sy0">,</span> <span class="nu0">2</span><span class="br0">&#41;</span> <span class="br0">&#125;</span><span class="br0">&#125;</span><span class="sy0">,</span>
&nbsp;
     <span class="sy0">@</span><span class="br0">&#123;</span>Name<span class="sy0">=</span><span class="st0">'FreeSpacePercent'</span>; Expression<span class="sy0">=</span><span class="br0">&#123;</span>
&nbsp;
    <span class="kw3">if</span> <span class="br0">&#40;</span><a href="about:blank"><span class="kw6">$_</span></a>.Size <span class="kw4">-gt</span> 0<span class="br0">&#41;</span> <span class="br0">&#123;</span>
&nbsp;
        <span class="re0">$sizeMB</span> <span class="sy0">=</span> <span class="br0">[</span>math<span class="br0">]</span>::Round<span class="br0">&#40;</span><a href="about:blank"><span class="kw6">$_</span></a>.Size <span class="sy0">/</span> 1MB<span class="sy0">,</span> 2<span class="br0">&#41;</span>
&nbsp;
        <span class="re0">$availMB</span> <span class="sy0">=</span> <span class="br0">[</span>math<span class="br0">]</span>::Round<span class="br0">&#40;</span><a href="about:blank"><span class="kw6">$_</span></a>.AvailableSpace <span class="sy0">/</span> 1MB<span class="sy0">,</span> 2<span class="br0">&#41;</span>
&nbsp;
        <span class="br0">[</span>math<span class="br0">]</span>::Round<span class="br0">&#40;</span><span class="br0">&#40;</span><span class="re0">$availMB</span> <span class="sy0">/</span> <span class="re0">$sizeMB</span><span class="br0">&#41;</span> <span class="sy0">*</span> 100<span class="sy0">,</span> 2<span class="br0">&#41;</span>
&nbsp;
        <span class="br0">&#125;</span> <span class="kw3">else</span> <span class="br0">&#123;</span> <span class="nu0">0</span> <span class="br0">&#125;</span>
&nbsp;
    <span class="br0">&#125;</span><span class="br0">&#125;</span><span class="sy0">,</span>
&nbsp;
    <span class="sy0">@</span><span class="br0">&#123;</span>Name<span class="sy0">=</span><span class="st0">'CaptureTimestamp'</span>; Expression<span class="sy0">=</span><span class="br0">&#123;</span> <span class="kw1">Get-Date</span> <span class="kw5">-Format</span> <span class="st0">&quot;yyyy-MM-dd HH:mm:ss&quot;</span> <span class="br0">&#125;</span><span class="br0">&#125;</span>
&nbsp;
    <span class="sy0">|</span> <span class="kw1">Format-Table</span></pre></div></div>
<p>This converts all sizes to MB, which will make any mathematical operations much easier. I also included a custom object for DatabaseName, FileSpacePercent, and CaptureTimestamp. DatabaseName really just acts as a custom column name, which is necessary when loading the data into SQL.</p>
<h3>On To The Comparisons</h3>
<p>Now that we are getting only the data we need, we need to save it to a table so we can do point in time comparisons. As with everything else, DBATools makes this ridiculously easy. We just need to point it to an instance and a database, it will take care of the rest. Instead of piping our results to Format-Table, I am going to pipe them to a command that will build and load a SQL table:</p>
<div id="wpshdo_13" class="wp-synhighlighter-outer"><div id="wpshdt_13" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_13"></a><a id="wpshat_13" class="wp-synhighlighter-title" href="#codesyntax_13"  onClick="javascript:wpsh_toggleBlock(13)" title="Click to show/hide code block">Source code</a></td><td align="right"><a href="#codesyntax_13" onClick="javascript:wpsh_code(13)" title="Show code only"><img decoding="async" border="0" style="border: 0 none" src="https://sqlsolutionsgroup.com/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_13" onClick="javascript:wpsh_print(13)" title="Print code"><img decoding="async" border="0" style="border: 0 none" src="https://sqlsolutionsgroup.com/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="https://sqlsolutionsgroup.com/wp-content/plugins/wp-synhighlight/About.html" target="_blank" title="Show plugin information"><img decoding="async" border="0" style="border: 0 none" src="https://sqlsolutionsgroup.com/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_13" class="wp-synhighlighter-inner" style="display: block;"><pre class="php" style="font-family:monospace;"><span class="re0">$SqlInstance</span> <span class="sy0">=</span> <span class="st0">&quot;SSG-LT-KBURWELL&quot;</span>
&nbsp;
<span class="re0">$WriteInstance</span> <span class="sy0">=</span> <span class="st0">&quot;SSG-LT-KBURWELL&quot;</span>
&nbsp;
<span class="re0">$WriteDB</span> <span class="sy0">=</span> <span class="st0">&quot;DBA&quot;</span>
&nbsp;
<span class="re0">$WriteTable</span> <span class="sy0">=</span> <span class="st0">&quot;FileSizesAndUsage&quot;</span>
&nbsp;
Get<span class="sy0">-</span>DbaDbFile <span class="sy0">-</span>SqlInstance <span class="re0">$SqlInstance</span> <span class="sy0">-</span>ExcludeDatabase master<span class="sy0">,</span>model<span class="sy0">,</span>msdb<span class="sy0">,</span>tempdb <span class="sy0">|</span>
&nbsp;
    Select<span class="sy0">-</span>Object SqlInstance<span class="sy0">,</span> TypeDescription<span class="sy0">,</span> LogicalName<span class="sy0">,</span> PhysicalName<span class="sy0">,</span>
&nbsp;
     <span class="sy0">@</span><span class="br0">&#123;</span>Name<span class="sy0">=</span><span class="st_h">'DatabaseName'</span><span class="sy0">;</span> Expression<span class="sy0">=</span><span class="br0">&#123;</span><span class="re0">$_</span><span class="sy0">.</span>Database<span class="br0">&#125;</span><span class="br0">&#125;</span><span class="sy0">,</span>
&nbsp;
     <span class="sy0">@</span><span class="br0">&#123;</span>Name<span class="sy0">=</span><span class="st_h">'SizeMB'</span><span class="sy0">;</span> Expression<span class="sy0">=</span><span class="br0">&#123;</span> <span class="br0">[</span>math<span class="br0">]</span><span class="sy0">::</span><a href="http://www.php.net/round"><span class="kw3">Round</span></a><span class="br0">&#40;</span><span class="re0">$_</span><span class="sy0">.</span>Size <span class="sy0">/</span> 1MB<span class="sy0">,</span> <span class="nu0">2</span><span class="br0">&#41;</span> <span class="br0">&#125;</span><span class="br0">&#125;</span><span class="sy0">,</span>
&nbsp;
     <span class="sy0">@</span><span class="br0">&#123;</span>Name<span class="sy0">=</span><span class="st_h">'UsedSpaceMB'</span><span class="sy0">;</span> Expression<span class="sy0">=</span><span class="br0">&#123;</span> <span class="br0">[</span>math<span class="br0">]</span><span class="sy0">::</span><a href="http://www.php.net/round"><span class="kw3">Round</span></a><span class="br0">&#40;</span><span class="re0">$_</span><span class="sy0">.</span>UsedSpace <span class="sy0">/</span> 1MB<span class="sy0">,</span> <span class="nu0">2</span><span class="br0">&#41;</span> <span class="br0">&#125;</span><span class="br0">&#125;</span><span class="sy0">,</span>
&nbsp;
     <span class="sy0">@</span><span class="br0">&#123;</span>Name<span class="sy0">=</span><span class="st_h">'AvailableSpaceMB'</span><span class="sy0">;</span> Expression<span class="sy0">=</span><span class="br0">&#123;</span> <span class="br0">[</span>math<span class="br0">]</span><span class="sy0">::</span><a href="http://www.php.net/round"><span class="kw3">Round</span></a><span class="br0">&#40;</span><span class="re0">$_</span><span class="sy0">.</span>AvailableSpace <span class="sy0">/</span> 1MB<span class="sy0">,</span> <span class="nu0">2</span><span class="br0">&#41;</span> <span class="br0">&#125;</span><span class="br0">&#125;</span><span class="sy0">,</span>
&nbsp;
     <span class="sy0">@</span><span class="br0">&#123;</span>Name<span class="sy0">=</span><span class="st_h">'FreeSpacePercent'</span><span class="sy0">;</span> Expression<span class="sy0">=</span><span class="br0">&#123;</span>
&nbsp;
    <span class="kw1">if</span> <span class="br0">&#40;</span><span class="re0">$_</span><span class="sy0">.</span>Size <span class="sy0">-</span>gt 0<span class="br0">&#41;</span> <span class="br0">&#123;</span>
&nbsp;
        <span class="re0">$sizeMB</span> <span class="sy0">=</span> <span class="br0">[</span>math<span class="br0">]</span><span class="sy0">::</span><a href="http://www.php.net/round"><span class="kw3">Round</span></a><span class="br0">&#40;</span><span class="re0">$_</span><span class="sy0">.</span>Size <span class="sy0">/</span> 1MB<span class="sy0">,</span> 2<span class="br0">&#41;</span>
&nbsp;
        <span class="re0">$availMB</span> <span class="sy0">=</span> <span class="br0">[</span>math<span class="br0">]</span><span class="sy0">::</span><a href="http://www.php.net/round"><span class="kw3">Round</span></a><span class="br0">&#40;</span><span class="re0">$_</span><span class="sy0">.</span>AvailableSpace <span class="sy0">/</span> 1MB<span class="sy0">,</span> 2<span class="br0">&#41;</span>
&nbsp;
        <span class="br0">[</span>math<span class="br0">]</span><span class="sy0">::</span><a href="http://www.php.net/round"><span class="kw3">Round</span></a><span class="br0">&#40;</span><span class="br0">&#40;</span><span class="re0">$availMB</span> <span class="sy0">/</span> <span class="re0">$sizeMB</span><span class="br0">&#41;</span> <span class="sy0">*</span> 100<span class="sy0">,</span> 2<span class="br0">&#41;</span>
&nbsp;
        <span class="br0">&#125;</span> <span class="kw1">else</span> <span class="br0">&#123;</span> <span class="nu0">0</span> <span class="br0">&#125;</span>
&nbsp;
    <span class="br0">&#125;</span><span class="br0">&#125;</span><span class="sy0">,</span>
&nbsp;
    <span class="sy0">@</span><span class="br0">&#123;</span>Name<span class="sy0">=</span><span class="st_h">'CaptureTimestamp'</span><span class="sy0">;</span> Expression<span class="sy0">=</span><span class="br0">&#123;</span> Get<span class="sy0">-</span><a href="http://www.php.net/date"><span class="kw3">Date</span></a> <span class="sy0">-</span>Format <span class="st0">&quot;yyyy-MM-dd HH:mm:ss&quot;</span> <span class="br0">&#125;</span><span class="br0">&#125;</span>
&nbsp;
    <span class="sy0">|</span> Write<span class="sy0">-</span>DbaDbTableData <span class="sy0">-</span>SqlInstance <span class="re0">$WriteInstance</span> <span class="sy0">-</span>Database <span class="re0">$WriteDB</span> <span class="sy0">-</span>Table <span class="re0">$WriteTable</span> <span class="sy0">-</span>AutoCreateTable</pre></div></div>
<p>Now I have the data in SQL Server:</p>
<p><img loading="lazy" decoding="async" class="alignnone wp-image-7351" src="https://sqlsolutionsgroup.com/wp-content/uploads/2025/12/a-screenshot-of-a-computer-ai-generated-content-m-1.png" alt="track database file sizes with Powershell" width="1267" height="207" srcset="https://sqlsolutionsgroup.com/wp-content/uploads/2025/12/a-screenshot-of-a-computer-ai-generated-content-m-1.png 1267w, https://sqlsolutionsgroup.com/wp-content/uploads/2025/12/a-screenshot-of-a-computer-ai-generated-content-m-1-300x49.png 300w, https://sqlsolutionsgroup.com/wp-content/uploads/2025/12/a-screenshot-of-a-computer-ai-generated-content-m-1-1024x167.png 1024w, https://sqlsolutionsgroup.com/wp-content/uploads/2025/12/a-screenshot-of-a-computer-ai-generated-content-m-1-768x125.png 768w" sizes="(max-width: 1267px) 100vw, 1267px" /></p>
<p>With this information being collected regularly, via scheduled task or agent job, we can easily trend out how much our database files are growing. It will also make potential misconfigurations stand out, such as a 1TB mdf with 99% free space. Personally, I use it in client environments to find over-allocated files that can be shrunk to reclaim some space. I know, “shrink bad”, but sometimes you just need to do it. As you can see, it&#8217;s quite straightforward and rather easy to track database file sizes with Powershell!</p>
<p>The post <a href="https://sqlsolutionsgroup.com/track-database-file-sizes-with-powershell/">Track Database File Sizes with PowerShell: A Quick Guide for DBAs</a> appeared first on <a href="https://sqlsolutionsgroup.com">SQL Solutions Group</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://sqlsolutionsgroup.com/track-database-file-sizes-with-powershell/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
			</item>
		<item>
		<title>A Common Misconception About SQL Server Backups</title>
		<link>https://sqlsolutionsgroup.com/a-common-misconception-about-sql-server-backups/</link>
		
		<dc:creator><![CDATA[Kyle Burwell]]></dc:creator>
		<pubDate>Mon, 14 Jul 2025 22:05:27 +0000</pubDate>
				<category><![CDATA[SQL Server]]></category>
		<guid isPermaLink="false">https://sqlsolutionsgroup.com/?p=7266</guid>

					<description><![CDATA[<p>The misconception about SQL Server backups: file-level backups are the same thing or as good as a native SQL Server backup of the database.</p>
<p>The post <a href="https://sqlsolutionsgroup.com/a-common-misconception-about-sql-server-backups/">A Common Misconception About SQL Server Backups</a> appeared first on <a href="https://sqlsolutionsgroup.com">SQL Solutions Group</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p class="wp-block-paragraph">I find there is a common misconception about SQL Server backups, and I find it when I ask, &#8220;When were these databases last backed up?&#8221; In fact, I ask myself this question every time I connect to a SQL Server instance for the first time.</p>



<p class="wp-block-paragraph">Then I go and find the answer myself. There are a bunch of ways to get this info, but I find querying MSDB the easiest:</p>


<div id="wpshdo_14" class="wp-synhighlighter-outer"><div id="wpshdt_14" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_14"></a><a id="wpshat_14" class="wp-synhighlighter-title" href="#codesyntax_14"  onClick="javascript:wpsh_toggleBlock(14)" title="Click to show/hide code block">Source code</a></td><td align="right"><a href="#codesyntax_14" onClick="javascript:wpsh_code(14)" title="Show code only"><img decoding="async" border="0" style="border: 0 none" src="https://sqlsolutionsgroup.com/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_14" onClick="javascript:wpsh_print(14)" title="Print code"><img decoding="async" border="0" style="border: 0 none" src="https://sqlsolutionsgroup.com/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="https://sqlsolutionsgroup.com/wp-content/plugins/wp-synhighlight/About.html" target="_blank" title="Show plugin information"><img decoding="async" border="0" style="border: 0 none" src="https://sqlsolutionsgroup.com/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_14" class="wp-synhighlighter-inner" style="display: block;"><pre class="tsql" style="font-family:monospace;"><span class="kw1">SELECT</span> d.<span class="me1">name</span> database_name
&nbsp;
,<span class="kw2">MAX</span><span class="br0">&#40;</span>backup_finish_date<span class="br0">&#41;</span> last_backup_date
&nbsp;
,<span class="kw1">CURRENT_TIMESTAMP</span> right_now
&nbsp;
<span class="kw1">FROM</span> sys.<span class="me1">databases</span> d <span class="kw1">LEFT</span> join msdb.<span class="me1">dbo</span>.<span class="me1">backupset</span> b <span class="kw1">ON</span> d.<span class="me1">name</span> <span class="sy0">=</span> b.<span class="me1">database_name</span> and b.<span class="me1">type</span> <span class="sy0">=</span> <span class="st0">'D'</span> <span class="sy0">-</span>–<span class="kw1">ONLY</span> concerned about FULLs <span class="kw1">RIGHT</span> now
&nbsp;
<span class="kw1">GROUP</span> <span class="kw1">BY</span> d.<span class="me1">name</span></pre></div></div>



<p class="wp-block-paragraph"></p>



<figure class="wp-block-image size-full is-resized"><img loading="lazy" decoding="async" width="448" height="57" src="https://sqlsolutionsgroup.com/wp-content/uploads/2025/07/Backups1.png" alt="" class="wp-image-7271" style="width:542px;height:auto" srcset="https://sqlsolutionsgroup.com/wp-content/uploads/2025/07/Backups1.png 448w, https://sqlsolutionsgroup.com/wp-content/uploads/2025/07/Backups1-300x38.png 300w" sizes="(max-width: 448px) 100vw, 448px" /><figcaption class="wp-element-caption"><strong>That&#8217;s not good.</strong></figcaption></figure>



<p class="has-text-align-left wp-block-paragraph"></p>



<p class="wp-block-paragraph">Now I know that I need to dig deeper into the backup strategy in place. This typically starts with firing off a couple of questions to whomever is responsible for the database.</p>



<ol class="wp-block-list">
<li>Did you know that we&#8217;re not backing up (insert database name here)?</li>



<li>Is this intentional?</li>
</ol>



<p class="wp-block-paragraph">During the conversation that follows, it sometimes comes to light that the database owner does have backups configured for the database in question, or at least they think they do. This is where the misconception about SQL Server backups comes in: that file-level backups of the database files are the same thing or as good as a native SQL Server backup of the database. <strong>This&nbsp; simply isn’t true</strong>.</p>



<h3 class="wp-block-heading">The Key Differences</h3>



<p class="wp-block-paragraph">While they both have their uses and can definitely be used in conjunction with one another, <strong>you need to have native SQL backups of your databases</strong>.</p>



<p class="wp-block-paragraph"><em><strong>Why?</strong></em> There are dozens of reasons, but here are the two I bring up the most:</p>



<ol class="wp-block-list">
<li><strong>Transaction safety/consistency</strong>: Native backups maintain ACID compliance while file-level backups may capture transactions in-flight.</li>



<li><strong>RTO/RPO</strong>: Native backups, when configured correctly, make Point-in-time recovery possible. You don’t get this with file-level backups.</li>
</ol>



<p class="wp-block-paragraph">This isn’t to say that you can’t or shouldn&#8217;t use a third party utility to perform these backups; some of those utilities integrate really well with SQL Server. You just need to know <strong>what is being backed up and how to verify</strong>. This is where MSDB comes in again. Even third&nbsp;party utilities will generate a record when they perform a native SQL Server backup:</p>



<figure class="wp-block-image is-resized"><img loading="lazy" decoding="async" width="446" height="54" src="https://sqlsolutionsgroup.com/wp-content/uploads/2025/07/word-image-7266-2.png" alt="" class="wp-image-7268" style="width:540px;height:auto" srcset="https://sqlsolutionsgroup.com/wp-content/uploads/2025/07/word-image-7266-2.png 446w, https://sqlsolutionsgroup.com/wp-content/uploads/2025/07/word-image-7266-2-300x36.png 300w" sizes="(max-width: 446px) 100vw, 446px" /><figcaption class="wp-element-caption"><strong>That&#8217;s better.</strong></figcaption></figure>



<p class="wp-block-paragraph"></p>



<p class="wp-block-paragraph">So in sum, file-level backups are great. Just make sure you are also performing and testing native backups. And don’t forget your system databases!</p>
<p>The post <a href="https://sqlsolutionsgroup.com/a-common-misconception-about-sql-server-backups/">A Common Misconception About SQL Server Backups</a> appeared first on <a href="https://sqlsolutionsgroup.com">SQL Solutions Group</a>.</p>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
