<?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>PeetersOnline &#187; SQL</title>
	<atom:link href="http://www.peetersonline.nl/index.php/category/sql/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.peetersonline.nl</link>
	<description>Using Powershell for (virtually) everything!</description>
	<lastBuildDate>Fri, 19 Aug 2011 09:22:19 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Get SQL database size using Windows Powershell</title>
		<link>http://www.peetersonline.nl/index.php/powershell/get-sql-database-size-using-windows-powershell/</link>
		<comments>http://www.peetersonline.nl/index.php/powershell/get-sql-database-size-using-windows-powershell/#comments</comments>
		<pubDate>Tue, 26 May 2009 09:13:33 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[Scripts]]></category>

		<guid isPermaLink="false">http://www.peetersonline.nl/?p=383</guid>
		<description><![CDATA[The following script examines servers from (part of) your Active Directory domain, identifies SQL servers and lists the instances with their total database sizes. # Get-SQLSizes.ps1 # Created by Hugo Peeters # http://www.peetersonline.nl # Description: Finds SQL Servers in Active Directory and gets the total database size in GB. &#160; #Region VARIABLES $SearchRoot = &#34;OU=Servers,DC=domain,DC=local&#34; <a href='http://www.peetersonline.nl/index.php/powershell/get-sql-database-size-using-windows-powershell/'>[...]</a>
No related posts.]]></description>
			<content:encoded><![CDATA[<p>The following script examines servers from (part of) your Active Directory domain, identifies SQL servers and lists the instances with their total database sizes.</p>
<p><span id="more-383"></span></p>

<div class="wp_syntax"><div class="code"><pre class="powershell" style="font-family:monospace;"><span style="color: #008000;"># Get-SQLSizes.ps1</span>
<span style="color: #008000;"># Created by Hugo Peeters</span>
<span style="color: #008000;"># http://www.peetersonline.nl</span>
<span style="color: #008000;"># Description: Finds SQL Servers in Active Directory and gets the total database size in GB.</span>
&nbsp;
<span style="color: #008000;">#Region VARIABLES</span>
	<span style="color: #800080;">$SearchRoot</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;OU=Servers,DC=domain,DC=local&quot;</span>
	<span style="color: #800080;">$OutFile</span> <span style="color: pink;">=</span> <span style="color: #800000;">'D:\scripts\SQLSizes.csv'</span>
	<span style="color: #800080;">$Digits</span> <span style="color: pink;">=</span> <span style="color: #804000;">2</span>
<span style="color: #008000;">#EndRegion VARIABLES</span>
&nbsp;
<span style="color: #008000;">#Region SCRIPT</span>
	<span style="color: #000000;">&#91;</span><span style="color: #008080;">System.Reflection.Assembly</span><span style="color: #000000;">&#93;</span>::<span style="color: #800000;">LoadWithPartialName</span><span style="color: #000000;">&#40;</span><span style="color: #800000;">'Microsoft.SqlServer.Smo'</span><span style="color: #000000;">&#41;</span> <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">Out-Null</span>
	<span style="color: #800080;">$myCol</span> <span style="color: pink;">=</span> <span style="color: pink;">@</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
	<span style="color: #0000FF;">ForEach</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$Server</span> <span style="color: #0000FF;">in</span> <span style="color: #000000;">&#40;</span>Get<span style="color: pink;">-</span>QADComputer <span style="color: pink;">-</span>SearchRoot <span style="color: #800080;">$SearchRoot</span> <span style="color: pink;">-</span>SizeLimit <span style="color: #804000;">0</span> <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">Sort</span> Name<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
		<span style="color: #000000;">&#123;</span>
		<span style="color: #0000FF;">ForEach</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$Instance</span> <span style="color: #0000FF;">in</span> <span style="color: #000000;">&#40;</span><span style="color: #008080; font-weight: bold;">Get-WmiObject</span> <span style="color: #008080; font-style: italic;">-Class</span> Win32_Service <span style="color: #008080; font-style: italic;">-ComputerName</span> <span style="color: #800080;">$Server</span>.Name <span style="color: pink;">|</span> <span style="color: #0000FF;">Where</span> <span style="color: #000000;">&#123;</span><span style="color: #000080;">$_</span>.Name <span style="color: #FF0000;">-like</span> <span style="color: #800000;">'MSSQL$*'</span><span style="color: #000000;">&#125;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
			<span style="color: #000000;">&#123;</span>
			<span style="color: #0000FF;">If</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$Instance</span> <span style="color: #FF0000;">-eq</span> <span style="color: #800080;">$null</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#123;</span><span style="color: #0000FF;">break</span><span style="color: #000000;">&#125;</span>
			<span style="color: #008000;"># Connect to SQL</span>
			<span style="color: #800080;">$InstanceString</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;{0}\{1}&quot;</span> <span style="color: #FF0000;">-f</span> <span style="color: #800080;">$Server</span>.Name<span style="color: pink;">,</span> <span style="color: #800080;">$Instance</span>.Name.Split<span style="color: #000000;">&#40;</span><span style="color: #800000;">'$'</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#91;</span><span style="color: #804000;">1</span><span style="color: #000000;">&#93;</span>
			<span style="color: #800080;">$Sql</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">New-Object</span> <span style="color: #000000;">&#40;</span><span style="color: #800000;">'Microsoft.SqlServer.Management.Smo.Server'</span><span style="color: #000000;">&#41;</span> <span style="color: #800080;">$InstanceString</span>
			<span style="color: #008000;"># Gather information</span>
			<span style="color: #800080;">$myObj</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;&quot;</span> <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">Select</span> Instance<span style="color: pink;">,</span> TotalDBSizeGB
			<span style="color: #800080;">$myObj</span>.Instance <span style="color: pink;">=</span> <span style="color: #800080;">$InstanceString</span>
			<span style="color: #800080;">$myObj</span>.TotalDBSizeGB <span style="color: pink;">=</span> <span style="color: #000000;">&#91;</span>Math<span style="color: #000000;">&#93;</span>::Round<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span><span style="color: #800080;">$Sql</span>.Databases <span style="color: pink;">|</span> <span style="color: #0000FF;">ForEach</span> <span style="color: #000000;">&#123;</span><span style="color: #000080;">$_</span>.Size<span style="color: #000000;">&#125;</span> <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">Measure-Object</span> <span style="color: #008080; font-style: italic;">-Sum</span><span style="color: #000000;">&#41;</span>.Sum <span style="color: pink;">*</span> 1MB <span style="color: pink;">/</span> 1GB<span style="color: #000000;">&#41;</span><span style="color: pink;">,</span><span style="color: #800080;">$Digits</span><span style="color: #000000;">&#41;</span>
			<span style="color: #800080;">$myCol</span> <span style="color: pink;">+=</span> <span style="color: #800080;">$myObj</span>
			<span style="color: #008000;"># Cleanup</span>
			<span style="color: #008080; font-weight: bold;">Clear-Variable</span> Sql <span style="color: #008080; font-style: italic;">-ErrorAction</span> SilentlyContinue
			<span style="color: #008080; font-weight: bold;">Clear-Variable</span> InstanceString <span style="color: #008080; font-style: italic;">-ErrorAction</span> SilentlyContinue
			<span style="color: #000000;">&#125;</span>
		<span style="color: #000000;">&#125;</span>	
<span style="color: #008000;">#EndRegion SCRIPT</span>
&nbsp;
<span style="color: #008000;">#Region OUTPUT</span>
	<span style="color: #800080;">$myCol</span> <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">Export-Csv</span> <span style="color: #800080;">$OutFile</span> <span style="color: #008080; font-style: italic;">-NoTypeInformation</span>
	<span style="color: #008080; font-weight: bold;">Invoke-Item</span> <span style="color: #800080;">$OutFile</span>
<span style="color: #008000;">#EndRegion OUTPUT</span></pre></div></div>

<p>No related posts.</p>]]></content:encoded>
			<wfw:commentRss>http://www.peetersonline.nl/index.php/powershell/get-sql-database-size-using-windows-powershell/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Get SQL Log Messages with Windows Powershell</title>
		<link>http://www.peetersonline.nl/index.php/powershell/get-sql-log-messages-with-windows-powershell/</link>
		<comments>http://www.peetersonline.nl/index.php/powershell/get-sql-log-messages-with-windows-powershell/#comments</comments>
		<pubDate>Thu, 04 Dec 2008 09:15:11 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[Log]]></category>

		<guid isPermaLink="false">http://www.peetersonline.nl/?p=113</guid>
		<description><![CDATA[Here&#8217;s a little something for the sysadmin that monitors SQL servers (who doesn&#8217;t?). This handy little function retrieves SQL log messages for a specified instance. You can also specify how many of the most recent messages to retrieve. function Get-SQLLog { param([string]$Instance, [Int]$SizeLimit = 10) If ($Instance -eq $null){Write-Warning &#8220;Syntax: Get-SQLLog [-Instance] [[-SizeLimit] ]&#8221;} Else <a href='http://www.peetersonline.nl/index.php/powershell/get-sql-log-messages-with-windows-powershell/'>[...]</a>
No related posts.]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s a little something for the sysadmin that monitors SQL servers (who doesn&#8217;t?). This handy little function retrieves SQL log messages for a specified instance. You can also specify how many of the most recent messages to retrieve.</p>
<blockquote><p>function Get-SQLLog<br />
	{<br />
	param([string]$Instance, [Int]$SizeLimit = 10)<br />
	If ($Instance -eq $null){Write-Warning &#8220;Syntax: Get-SQLLog [-Instance] <SERVER\INSTANCE> [[-SizeLimit] <Int>]&#8221;}<br />
	Else<br />
	{<br />
	[System.Reflection.Assembly]::LoadWithPartialName(&#8216;<a href="http://www.microsoft.com" target='_blank'>Microsoft</a>.SqlServer.Smo&#8217;) | Out-Null<br />
	$Sql = New-Object (&#8216;<a href="http://www.microsoft.com" target='_blank'>Microsoft</a>.SqlServer.Management.Smo.Server&#8217;) $Instance<br />
	$sql.ReadErrorLog() | select -last $SizeLimit<br />
	}<br />
	}</p>
</blockquote>
<p>No related posts.</p>]]></content:encoded>
			<wfw:commentRss>http://www.peetersonline.nl/index.php/powershell/get-sql-log-messages-with-windows-powershell/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

