<?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>youdidwhatwithtsql.com</title>
	<atom:link href="http://www.youdidwhatwithtsql.com/feed" rel="self" type="application/rss+xml" />
	<link>http://www.youdidwhatwithtsql.com</link>
	<description>making DBAs everywhere curse!</description>
	<lastBuildDate>Tue, 31 Jan 2012 12:21:23 +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>Check Mirroring Status with Powershell</title>
		<link>http://www.youdidwhatwithtsql.com/check-mirroring-status-powershell/1436</link>
		<comments>http://www.youdidwhatwithtsql.com/check-mirroring-status-powershell/1436#comments</comments>
		<pubDate>Tue, 31 Jan 2012 12:21:23 +0000</pubDate>
		<dc:creator>Rhys</dc:creator>
				<category><![CDATA[DBA]]></category>
		<category><![CDATA[Powershell]]></category>
		<category><![CDATA[mirroring]]></category>
		<category><![CDATA[SQL Server]]></category>

		<guid isPermaLink="false">http://www.youdidwhatwithtsql.com/?p=1436</guid>
		<description><![CDATA[Here&#8217;s a simple Powershell snippet to check the mirroring status on your SQL Server instances. ?View Code POWERSHELL# Load SMO extension &#91;System.Reflection.Assembly&#93;::LoadWithPartialName&#40;&#34;Microsoft.SqlServer.Smo&#34;&#41; &#124; Out-Null; &#160; # Servers to check $sqlservers = @&#40;&#34;server1&#34;, &#34;server2&#34;, &#34;server3&#34;&#41;; foreach&#40;$server in $sqlservers&#41; &#123; $srv = New-Object &#34;Microsoft.SqlServer.Management.Smo.Server&#34; $server; # Get mirrored databases $databases = $srv.Databases &#124; Where-Object &#123;$_.IsMirroringEnabled -eq $true&#125;; Write-Host [...]<p>Post from: <a href="http://www.youdidwhatwithtsql.com">youdidwhatwithtsql.com</a><br/><br/><a href="http://www.youdidwhatwithtsql.com/check-mirroring-status-powershell/1436">Check Mirroring Status with Powershell</a></p>
]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s a simple <a title="Windows Powershell" href="http://technet.microsoft.com/en-us/scriptcenter/dd742419" target="_blank">Powershell</a> snippet to check the <a title="SQL Server Mirroring Status" href="http://msdn.microsoft.com/en-us/library/ms365781.aspx" target="_blank">mirroring status</a> on your SQL Server instances.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p1436code2'); return false;">View Code</a> POWERSHELL</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p14362"><td class="code" id="p1436code2"><pre class="powershell" style="font-family:monospace;"><span style="color: #008000;"># Load SMO extension</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;">&quot;Microsoft.SqlServer.Smo&quot;</span><span style="color: #000000;">&#41;</span> <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">Out-Null</span>;
&nbsp;
<span style="color: #008000;"># Servers to check</span>
<span style="color: #800080;">$sqlservers</span> <span style="color: pink;">=</span> <span style="color: pink;">@</span><span style="color: #000000;">&#40;</span><span style="color: #800000;">&quot;server1&quot;</span><span style="color: pink;">,</span> <span style="color: #800000;">&quot;server2&quot;</span><span style="color: pink;">,</span> <span style="color: #800000;">&quot;server3&quot;</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: #800080;">$sqlservers</span><span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
	<span style="color: #800080;">$srv</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">New-Object</span> <span style="color: #800000;">&quot;Microsoft.SqlServer.Management.Smo.Server&quot;</span> <span style="color: #800080;">$server</span>;
	<span style="color: #008000;"># Get mirrored databases</span>
	<span style="color: #800080;">$databases</span> <span style="color: pink;">=</span> <span style="color: #800080;">$srv</span>.Databases <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">Where-Object</span> <span style="color: #000000;">&#123;</span><span style="color: #000080;">$_</span>.IsMirroringEnabled <span style="color: #FF0000;">-eq</span> <span style="color: #800080;">$true</span><span style="color: #000000;">&#125;</span>; 
	<span style="color: #008080; font-weight: bold;">Write-Host</span> <span style="color: #800080;">$server</span>;
	<span style="color: #008080; font-weight: bold;">Write-Host</span> <span style="color: #800000;">&quot;==================================&quot;</span>;
	<span style="color: #800080;">$databases</span> <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">Select-Object</span> <span style="color: #008080; font-style: italic;">-Property</span> Name<span style="color: pink;">,</span> MirroringStatus <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">Format-Table</span> <span style="color: #008080; font-style: italic;">-AutoSize</span>;
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p>This will output something looking like below&#8230;</p>
<pre>server1
====================================

Name                 MirroringStatus
----                 ---------------
db1         		Synchronized
db2                    	Synchronized
db3              	Synchronized
db4			Synchronized
db5    			Synchronized
server2
=====================================

Name                 MirroringStatus
----                 ---------------
db1         		Synchronized
db2                    	Synchronized
db3              	Synchronized
db4			Synchronized
db5    			Synchronized
server3
=====================================

Name                 MirroringStatus
----                 ---------------
db1         		Synchronized
db2                    	Synchronized
db3              	Synchronized
db4			Synchronized
db5    			Synchronized</pre>
<p><map name='google_ad_map_1436_a45beff5d2e172f6'>
<area shape='rect' href='http://imageads.googleadservices.com/pagead/imgclick/1436?pos=0' coords='1,2,367,28' />
<area shape='rect' href='http://services.google.com/feedback/abg' coords='384,10,453,23'/></map>
<img usemap='#google_ad_map_1436_a45beff5d2e172f6' border='0' src='http://imageads.googleadservices.com/pagead/ads?format=468x30_aff_img&amp;client=&amp;channel=&amp;output=png&amp;cuid=1436&amp;url=http%3A%2F%2Fwww.youdidwhatwithtsql.com%2Fcheck-mirroring-status-powershell%2F1436' title="Check Mirroring Status with Powershell" alt=" Check Mirroring Status with Powershell" /></p><p>Post from: <a href="http://www.youdidwhatwithtsql.com">youdidwhatwithtsql.com</a><br/><br/><a href="http://www.youdidwhatwithtsql.com/check-mirroring-status-powershell/1436">Check Mirroring Status with Powershell</a></p>
<div class="none"><div class="g-plusone" data-href="http://www.youdidwhatwithtsql.com/check-mirroring-status-powershell/1436" size="standard" count="true"></div></div>]]></content:encoded>
			<wfw:commentRss>http://www.youdidwhatwithtsql.com/check-mirroring-status-powershell/1436/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Get-ServerErrors Powershell Function</title>
		<link>http://www.youdidwhatwithtsql.com/getservererrors-powershell-function/1431</link>
		<comments>http://www.youdidwhatwithtsql.com/getservererrors-powershell-function/1431#comments</comments>
		<pubDate>Fri, 06 Jan 2012 16:57:26 +0000</pubDate>
		<dc:creator>Rhys</dc:creator>
				<category><![CDATA[DBA]]></category>
		<category><![CDATA[Powershell]]></category>

		<guid isPermaLink="false">http://www.youdidwhatwithtsql.com/?p=1431</guid>
		<description><![CDATA[Here&#8217;s a little Powershell function I&#8217;m using to check the Event Logs and SQL Server Error Logs in one easy swoop; ?View Code POWERSHELLfunction Get-ServerErrors &#123; # Server to check &#38;amp; hours back. Will only support default sql instances # Could add a third param for instance and modify script where appropriate if needed param &#40;$server, [...]<p>Post from: <a href="http://www.youdidwhatwithtsql.com">youdidwhatwithtsql.com</a><br/><br/><a href="http://www.youdidwhatwithtsql.com/getservererrors-powershell-function/1431">Get-ServerErrors Powershell Function</a></p>
]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s a little Powershell function I&#8217;m using to check the <a title="Windows Event Logs" href="http://technet.microsoft.com/en-us/library/cc722404.aspx" target="_blank">Event Logs</a> and <a title="SQL server Error Logs" href="http://sqlserverpedia.com/wiki/SQL_Server_Error_Logs" target="_blank">SQL Server Error Logs</a> in one easy swoop;</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p1431code5'); return false;">View Code</a> POWERSHELL</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p14315"><td class="code" id="p1431code5"><pre class="powershell" style="font-family:monospace;"><span style="color: #0000FF;">function</span> Get<span style="color: pink;">-</span>ServerErrors
<span style="color: #000000;">&#123;</span>
	<span style="color: #008000;"># Server to check &amp;amp; hours back. Will only support default sql instances</span>
	<span style="color: #008000;"># Could add a third param for instance and modify script where appropriate if needed</span>
	<span style="color: #0000FF;">param</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$server</span><span style="color: pink;">,</span> <span style="color: #000000;">&#91;</span><span style="color: #008080;">int</span><span style="color: #000000;">&#93;</span><span style="color: #800080;">$hours</span><span style="color: #000000;">&#41;</span>;
&nbsp;
	<span style="color: #000000;">&#91;</span>datetime<span style="color: #000000;">&#93;</span><span style="color: #800080;">$after</span> <span style="color: pink;">=</span> $<span style="color: #000000;">&#40;</span><span style="color: #008080; font-weight: bold;">Get-Date</span><span style="color: #000000;">&#41;</span>.AddHours<span style="color: #000000;">&#40;</span><span style="color: pink;">-</span><span style="color: #800080;">$hours</span><span style="color: #000000;">&#41;</span>;
&nbsp;
	<span style="color: #008000;"># Windows Event Log (Application &amp;amp; System) Errors &amp;amp; Warnings</span>
&nbsp;
	<span style="color: #008080; font-weight: bold;">Write-Host</span> <span style="color: #800000;">&quot;Application Event Log Errors from $server after $after&quot;</span>;
	<span style="color: #008080; font-weight: bold;">Write-Host</span> <span style="color: #800000;">&quot;========================================================================&quot;</span>;
	<span style="color: #008080; font-weight: bold;">Get-EventLog</span> <span style="color: #008080; font-style: italic;">-ComputerName</span> <span style="color: #800080;">$server</span> <span style="color: #008080; font-style: italic;">-LogName</span> <span style="color: #800000;">&quot;Application&quot;</span> <span style="color: pink;">-</span>EntryType <span style="color: #800000;">&quot;Error&quot;</span> <span style="color: pink;">-</span>After <span style="color: #800080;">$after</span> <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">Format-List</span>;
	<span style="color: #008080; font-weight: bold;">Write-Host</span> <span style="color: #800000;">&quot;Press any key to continue or ctrl + c to quit&quot;</span>;
	<span style="color: #800080;">$r</span> <span style="color: pink;">=</span> <span style="color: #800080;">$host</span>.UI.RawUI.ReadKey<span style="color: #000000;">&#40;</span><span style="color: #800000;">&quot;NoEcho,IncludeKeyDown&quot;</span><span style="color: #000000;">&#41;</span>;
&nbsp;
	<span style="color: #008080; font-weight: bold;">Write-Host</span> <span style="color: #800000;">&quot;System Event Log Errors from $server after $after&quot;</span>;
	<span style="color: #008080; font-weight: bold;">Write-Host</span> <span style="color: #800000;">&quot;========================================================================&quot;</span>;
	<span style="color: #008080; font-weight: bold;">Get-EventLog</span> <span style="color: #008080; font-style: italic;">-ComputerName</span> <span style="color: #800080;">$server</span> <span style="color: #008080; font-style: italic;">-LogName</span> <span style="color: #800000;">&quot;System&quot;</span> <span style="color: pink;">-</span>EntryType <span style="color: #800000;">&quot;Error&quot;</span> <span style="color: pink;">-</span>After <span style="color: #800080;">$after</span> <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">Format-List</span>;
	<span style="color: #008080; font-weight: bold;">Write-Host</span> <span style="color: #800000;">&quot;Press any key to continue or ctrl + c to quit&quot;</span>;
	<span style="color: #800080;">$r</span> <span style="color: pink;">=</span> <span style="color: #800080;">$host</span>.UI.RawUI.ReadKey<span style="color: #000000;">&#40;</span><span style="color: #800000;">&quot;NoEcho,IncludeKeyDown&quot;</span><span style="color: #000000;">&#41;</span>;
&nbsp;
	<span style="color: #008080; font-weight: bold;">Write-Host</span> <span style="color: #800000;">&quot;Application Event Log Warnings from $server after $after&quot;</span>;
	<span style="color: #008080; font-weight: bold;">Write-Host</span> <span style="color: #800000;">&quot;========================================================================&quot;</span>;
	<span style="color: #008080; font-weight: bold;">Get-EventLog</span> <span style="color: #008080; font-style: italic;">-ComputerName</span> <span style="color: #800080;">$server</span> <span style="color: #008080; font-style: italic;">-LogName</span> <span style="color: #800000;">&quot;Application&quot;</span> <span style="color: pink;">-</span>EntryType <span style="color: #800000;">&quot;Warning&quot;</span> <span style="color: pink;">-</span>After <span style="color: #800080;">$after</span> <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">Format-List</span>;
	<span style="color: #008080; font-weight: bold;">Write-Host</span> <span style="color: #800000;">&quot;Press any key to continue or ctrl + c to quit&quot;</span>;
	<span style="color: #800080;">$r</span> <span style="color: pink;">=</span> <span style="color: #800080;">$host</span>.UI.RawUI.ReadKey<span style="color: #000000;">&#40;</span><span style="color: #800000;">&quot;NoEcho,IncludeKeyDown&quot;</span><span style="color: #000000;">&#41;</span>;	
&nbsp;
	<span style="color: #008080; font-weight: bold;">Write-Host</span> <span style="color: #800000;">&quot;System Event Log Warnings from $server after $after&quot;</span>;
	<span style="color: #008080; font-weight: bold;">Write-Host</span> <span style="color: #800000;">&quot;========================================================================&quot;</span>;
	<span style="color: #008080; font-weight: bold;">Get-EventLog</span> <span style="color: #008080; font-style: italic;">-ComputerName</span> <span style="color: #800080;">$server</span> <span style="color: #008080; font-style: italic;">-LogName</span> <span style="color: #800000;">&quot;System&quot;</span> <span style="color: pink;">-</span>EntryType <span style="color: #800000;">&quot;Warning&quot;</span> <span style="color: pink;">-</span>After <span style="color: #800080;">$after</span> <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">Format-List</span>;
	<span style="color: #008080; font-weight: bold;">Write-Host</span> <span style="color: #800000;">&quot;Press any key to continue or ctrl + c to quit&quot;</span>;
	<span style="color: #800080;">$r</span> <span style="color: pink;">=</span> <span style="color: #800080;">$host</span>.UI.RawUI.ReadKey<span style="color: #000000;">&#40;</span><span style="color: #800000;">&quot;NoEcho,IncludeKeyDown&quot;</span><span style="color: #000000;">&#41;</span>;	
&nbsp;
	<span style="color: #008000;"># SQL Server Error Log</span>
	<span style="color: #000000;">&#91;</span>reflection.assembly<span style="color: #000000;">&#93;</span>::<span style="color: #800000;">LoadWithPartialName</span><span style="color: #000000;">&#40;</span><span style="color: #800000;">&quot;Microsoft.SqlServer.Smo&quot;</span><span style="color: #000000;">&#41;</span> ;
	<span style="color: #800080;">$sql_server</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;">&quot;Microsoft.SqlServer.Management.Smo.Server&quot;</span><span style="color: #000000;">&#41;</span> <span style="color: #800080;">$server</span>;
	<span style="color: #800080;">$sql_server</span>.ReadErrorLog<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">Where-Object</span> <span style="color: #000000;">&#123;</span><span style="color: #000080;">$_</span>.Text <span style="color: #FF0000;">-like</span> <span style="color: #800000;">&quot;Error*&quot;</span> <span style="color: #FF0000;">-and</span> <span style="color: #000080;">$_</span>.LogDate <span style="color: #FF0000;">-ge</span> <span style="color: #800080;">$after</span><span style="color: #000000;">&#125;</span>;
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p>Usage is as follows;</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p1431code6'); return false;">View Code</a> POWERSHELL</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p14316"><td class="code" id="p1431code6"><pre class="powershell" style="font-family:monospace;">Get<span style="color: pink;">-</span>ServerErrors <span style="color: pink;">&lt;</span>server name<span style="color: pink;">&gt;</span> <span style="color: pink;">&lt;</span>hours back to check<span style="color: pink;">&gt;</span>;</pre></td></tr></table></div>

<p><map name='google_ad_map_1431_a45beff5d2e172f6'>
<area shape='rect' href='http://imageads.googleadservices.com/pagead/imgclick/1431?pos=0' coords='1,2,367,28' />
<area shape='rect' href='http://services.google.com/feedback/abg' coords='384,10,453,23'/></map>
<img usemap='#google_ad_map_1431_a45beff5d2e172f6' border='0' src='http://imageads.googleadservices.com/pagead/ads?format=468x30_aff_img&amp;client=&amp;channel=&amp;output=png&amp;cuid=1431&amp;url=http%3A%2F%2Fwww.youdidwhatwithtsql.com%2Fgetservererrors-powershell-function%2F1431' title="Get ServerErrors Powershell Function" alt=" Get ServerErrors Powershell Function" /></p><p>Post from: <a href="http://www.youdidwhatwithtsql.com">youdidwhatwithtsql.com</a><br/><br/><a href="http://www.youdidwhatwithtsql.com/getservererrors-powershell-function/1431">Get-ServerErrors Powershell Function</a></p>
<div class="none"><div class="g-plusone" data-href="http://www.youdidwhatwithtsql.com/getservererrors-powershell-function/1431" size="standard" count="true"></div></div>]]></content:encoded>
			<wfw:commentRss>http://www.youdidwhatwithtsql.com/getservererrors-powershell-function/1431/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Working with multiple computers in Bash</title>
		<link>http://www.youdidwhatwithtsql.com/working-multiple-computers-bash/1427</link>
		<comments>http://www.youdidwhatwithtsql.com/working-multiple-computers-bash/1427#comments</comments>
		<pubDate>Fri, 30 Dec 2011 16:12:08 +0000</pubDate>
		<dc:creator>Rhys</dc:creator>
				<category><![CDATA[Bash]]></category>
		<category><![CDATA[Linux]]></category>

		<guid isPermaLink="false">http://www.youdidwhatwithtsql.com/?p=1427</guid>
		<description><![CDATA[Working with multiple computers in Powershell is absurdly easy using the Get-Content cmdlet to read computer names from a text file. It&#8217;s as easy as this&#8230; ?View Code POWERSHELL$a = Get-Content &#34;C:\Scripts\Test.txt&#34; &#160; foreach &#40;$i in $a&#41; &#123;$i + &#34;`n&#34; + &#34;==========================&#34;; Get-WMIObject Win32_BIOS -computername $i&#125; As I&#8217;m doing more and more bash scripting I thought [...]<p>Post from: <a href="http://www.youdidwhatwithtsql.com">youdidwhatwithtsql.com</a><br/><br/><a href="http://www.youdidwhatwithtsql.com/working-multiple-computers-bash/1427">Working with multiple computers in Bash</a></p>
]]></description>
			<content:encoded><![CDATA[<p>Working with <a href="http://technet.microsoft.com/en-us/library/ff730959.aspx" target="_blank">multiple computers in Powershell</a> is absurdly easy using the <a title="Windows Powershell Get-Content cmdlet" href="http://technet.microsoft.com/en-us/library/ee176843.aspx" target="_blank">Get-Content</a> cmdlet to read computer names from a text file. It&#8217;s as easy as this&#8230;</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p1427code9'); return false;">View Code</a> POWERSHELL</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p14279"><td class="code" id="p1427code9"><pre class="powershell" style="font-family:monospace;"><span style="color: #800080;">$a</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">Get-Content</span> <span style="color: #800000;">&quot;C:\Scripts\Test.txt&quot;</span>
&nbsp;
<span style="color: #0000FF;">foreach</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$i</span> <span style="color: #0000FF;">in</span> <span style="color: #800080;">$a</span><span style="color: #000000;">&#41;</span>
    <span style="color: #000000;">&#123;</span><span style="color: #800080;">$i</span> <span style="color: pink;">+</span> <span style="color: #800000;">&quot;<span style="color: #008080; font-weight: bold;">`n</span>&quot;</span> <span style="color: pink;">+</span> <span style="color: #800000;">&quot;==========================&quot;</span>; <span style="color: #008080; font-weight: bold;">Get-WMIObject</span> Win32_BIOS <span style="color: #008080; font-style: italic;">-computername</span> <span style="color: #800080;">$i</span><span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p>As I&#8217;m doing more and more bash scripting I thought it would be useful to replicate this. Here&#8217;s how you do it;</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p1427code10'); return false;">View Code</a> BASH</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p142710"><td class="code" id="p1427code10"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/bash</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">for</span> c <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">cat</span> computers.txt<span style="color: #000000; font-weight: bold;">`</span>
<span style="color: #000000; font-weight: bold;">do</span>
        <span style="color: #666666; font-style: italic;"># Do work with each computer here...</span>
        <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Computer = <span style="color: #007800;">$c</span>&quot;</span>;
<span style="color: #000000; font-weight: bold;">done</span></pre></td></tr></table></div>

<p><map name='google_ad_map_1427_a45beff5d2e172f6'>
<area shape='rect' href='http://imageads.googleadservices.com/pagead/imgclick/1427?pos=0' coords='1,2,367,28' />
<area shape='rect' href='http://services.google.com/feedback/abg' coords='384,10,453,23'/></map>
<img usemap='#google_ad_map_1427_a45beff5d2e172f6' border='0' src='http://imageads.googleadservices.com/pagead/ads?format=468x30_aff_img&amp;client=&amp;channel=&amp;output=png&amp;cuid=1427&amp;url=http%3A%2F%2Fwww.youdidwhatwithtsql.com%2Fworking-multiple-computers-bash%2F1427' title="Working with multiple computers in Bash" alt=" Working with multiple computers in Bash" /></p><p>Post from: <a href="http://www.youdidwhatwithtsql.com">youdidwhatwithtsql.com</a><br/><br/><a href="http://www.youdidwhatwithtsql.com/working-multiple-computers-bash/1427">Working with multiple computers in Bash</a></p>
<div class="none"><div class="g-plusone" data-href="http://www.youdidwhatwithtsql.com/working-multiple-computers-bash/1427" size="standard" count="true"></div></div>]]></content:encoded>
			<wfw:commentRss>http://www.youdidwhatwithtsql.com/working-multiple-computers-bash/1427/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>List AD Organizational Units with Powershell</title>
		<link>http://www.youdidwhatwithtsql.com/list-ad-organizational-units-powershell/1424</link>
		<comments>http://www.youdidwhatwithtsql.com/list-ad-organizational-units-powershell/1424#comments</comments>
		<pubDate>Fri, 30 Dec 2011 12:28:03 +0000</pubDate>
		<dc:creator>Rhys</dc:creator>
				<category><![CDATA[Powershell]]></category>

		<guid isPermaLink="false">http://www.youdidwhatwithtsql.com/?p=1424</guid>
		<description><![CDATA[Here&#8217;s a quick Powershell one-liner to list all the Organizational Units, or OUs, in your Active Directory domain. Firstly you&#8217;ll probably need to load the ActiveDirectory module. This can be done at the Powershell prompt with the below command; ?View Code POWERSHELLImport-Module ActiveDirectory; Then we can use the Get-ADOrganizationalUnit cmdlet to retrieve a list of [...]<p>Post from: <a href="http://www.youdidwhatwithtsql.com">youdidwhatwithtsql.com</a><br/><br/><a href="http://www.youdidwhatwithtsql.com/list-ad-organizational-units-powershell/1424">List AD Organizational Units with Powershell</a></p>
]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s a quick <a title="Windows Powershell" href="http://technet.microsoft.com/en-us/scriptcenter/dd742419">Powershell</a> one-liner to list all the <a title="Active Directory Organizational Unit" href="http://technet.microsoft.com/en-us/library/cc758565%28WS.10%29.aspx" target="_blank">Organizational Units</a>, or OUs, in your Active Directory domain. Firstly you&#8217;ll probably need to load the <a title="Powershell ActiveDirectory Module" href="http://technet.microsoft.com/en-us/library/ee617195.aspx" target="_blank">ActiveDirectory</a> module. This can be done at the Powershell prompt with the below command;</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p1424code13'); return false;">View Code</a> POWERSHELL</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p142413"><td class="code" id="p1424code13"><pre class="powershell" style="font-family:monospace;">Import<span style="color: pink;">-</span>Module ActiveDirectory;</pre></td></tr></table></div>

<p>Then we can use the <a title="Get-ADOrganizationalUnit Powershell cmdlet" href="http://technet.microsoft.com/en-us/library/ee617236.aspx" target="_blank">Get-ADOrganizationalUnit cmdlet </a>to retrieve a list of OUs.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p1424code14'); return false;">View Code</a> POWERSHELL</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p142414"><td class="code" id="p1424code14"><pre class="powershell" style="font-family:monospace;">Get<span style="color: pink;">-</span>ADOrganizationalUnit <span style="color: pink;">-</span><span style="color: #0000FF;">Filter</span> <span style="color: pink;">*</span> <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">Select-Object</span> <span style="color: #008080; font-style: italic;">-Property</span> Name <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">Format-Table</span> <span style="color: #008080; font-style: italic;">-AutoSize</span>;</pre></td></tr></table></div>

<p>This will display a list looking something like below;</p>
<pre>Name
----
Domain Controllers
Microsoft Exchange Security Groups
Security Groups
Domain Servers
Domain Workstations
Domain Guest Accounts
Printers
Management
Virtual Desktops
IT
Service Accounts
Users
Computers
Production Servers
SQL Servers
Web Servers</pre>
<p><map name='google_ad_map_1424_a45beff5d2e172f6'>
<area shape='rect' href='http://imageads.googleadservices.com/pagead/imgclick/1424?pos=0' coords='1,2,367,28' />
<area shape='rect' href='http://services.google.com/feedback/abg' coords='384,10,453,23'/></map>
<img usemap='#google_ad_map_1424_a45beff5d2e172f6' border='0' src='http://imageads.googleadservices.com/pagead/ads?format=468x30_aff_img&amp;client=&amp;channel=&amp;output=png&amp;cuid=1424&amp;url=http%3A%2F%2Fwww.youdidwhatwithtsql.com%2Flist-ad-organizational-units-powershell%2F1424' title="List AD Organizational Units with Powershell" alt=" List AD Organizational Units with Powershell" /></p><p>Post from: <a href="http://www.youdidwhatwithtsql.com">youdidwhatwithtsql.com</a><br/><br/><a href="http://www.youdidwhatwithtsql.com/list-ad-organizational-units-powershell/1424">List AD Organizational Units with Powershell</a></p>
<div class="none"><div class="g-plusone" data-href="http://www.youdidwhatwithtsql.com/list-ad-organizational-units-powershell/1424" size="standard" count="true"></div></div>]]></content:encoded>
			<wfw:commentRss>http://www.youdidwhatwithtsql.com/list-ad-organizational-units-powershell/1424/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Beware the Powershell -Contains operator</title>
		<link>http://www.youdidwhatwithtsql.com/beware-powershell-operator/1403</link>
		<comments>http://www.youdidwhatwithtsql.com/beware-powershell-operator/1403#comments</comments>
		<pubDate>Tue, 29 Nov 2011 12:20:00 +0000</pubDate>
		<dc:creator>Rhys</dc:creator>
				<category><![CDATA[Powershell]]></category>
		<category><![CDATA[contains]]></category>

		<guid isPermaLink="false">http://www.youdidwhatwithtsql.com/beware-the-powershell-contains-operator/1403</guid>
		<description><![CDATA[Many of us tend to jump quickly, into a new programming or scripting language, applying knowledge we&#8217;ve learned elsewhere to the current task at hand. Broadly speaking this works well but these always a little gotcha to trip you up! A good example is the Powershell -contains operator. It&#8217;s not like .Net String.Contains method as [...]<p>Post from: <a href="http://www.youdidwhatwithtsql.com">youdidwhatwithtsql.com</a><br/><br/><a href="http://www.youdidwhatwithtsql.com/beware-powershell-operator/1403">Beware the Powershell -Contains operator</a></p>
]]></description>
			<content:encoded><![CDATA[<p>Many of us tend to jump quickly, into a new programming or scripting language, applying knowledge we&#8217;ve learned elsewhere to the current task at hand. Broadly speaking this works well but these always a little <a title="Gotcha" href="http://en.wikipedia.org/wiki/Gotcha_(programming)" target="_blank">gotcha</a> to trip you up!</p>
<p>A good example is the Powershell -contains operator. It&#8217;s not like .Net <a title=".Net String.Contains method" href="http://msdn.microsoft.com/en-us/library/dy85x1sa.aspx" target="_blank">String.Contains</a> method as you might first think.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p1403code19'); return false;">View Code</a> POWERSHELL</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p140319"><td class="code" id="p1403code19"><pre class="powershell" style="font-family:monospace;"><span style="color: #800080;">$var</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;Rhys Campbell&quot;</span>;
<span style="color: #800080;">$var</span> <span style="color: #FF0000;">-contains</span> <span style="color: #800000;">&quot;Rhys&quot;</span>;</pre></td></tr></table></div>

<p>The result of this is <strong>false</strong>. Why? Because the <strong>-contains</strong> operator in Powershell is used for testing for <a title="Powershell -contains operator" href="http://technet.microsoft.com/en-us/library/ee692798.aspx" target="_blank">items in an array</a>.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p1403code20'); return false;">View Code</a> POWERSHELL</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p140320"><td class="code" id="p1403code20"><pre class="powershell" style="font-family:monospace;"><span style="color: #800080;">$var</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;Rhys Campbell&quot;</span><span style="color: pink;">,</span> <span style="color: #800000;">&quot;Joe Bloggs&quot;</span>;
<span style="color: #800080;">$var</span> <span style="color: #FF0000;">-contains</span> <span style="color: #800000;">&quot;Rhys Campbell&quot;</span>;</pre></td></tr></table></div>

<p>Will return <strong>true</strong>, but;</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p1403code21'); return false;">View Code</a> POWERSHELL</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p140321"><td class="code" id="p1403code21"><pre class="powershell" style="font-family:monospace;"><span style="color: #800080;">$var</span> <span style="color: #FF0000;">-contains</span> <span style="color: #800000;">&quot;Rhys*&quot;</span>;</pre></td></tr></table></div>

<p>Will return <strong>false</strong> as wildcards will not work as we assume they will. For wildcard matching we can use the <strong>-match</strong> operator.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p1403code22'); return false;">View Code</a> POWERSHELL</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p140322"><td class="code" id="p1403code22"><pre class="powershell" style="font-family:monospace;"><span style="color: #800080;">$var</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;Rhys Campbell&quot;</span>;
<span style="color: #800080;">$var</span> <span style="color: #FF0000;">-match</span> <span style="color: #800000;">&quot;Rhys&quot;</span>;</pre></td></tr></table></div>

<p>This will return <strong>true</strong> when matching simple strings or the matching items from an array of strings. Now I&#8217;m going to try and remember what <a href="http://www.youtube.com/watch?v=wg4trPZFUwc" target="_blank">assumption is the mother of</a> (NSFW, contains cussing).</p>
<p><map name='google_ad_map_1403_a45beff5d2e172f6'>
<area shape='rect' href='http://imageads.googleadservices.com/pagead/imgclick/1403?pos=0' coords='1,2,367,28' />
<area shape='rect' href='http://services.google.com/feedback/abg' coords='384,10,453,23'/></map>
<img usemap='#google_ad_map_1403_a45beff5d2e172f6' border='0' src='http://imageads.googleadservices.com/pagead/ads?format=468x30_aff_img&amp;client=&amp;channel=&amp;output=png&amp;cuid=1403&amp;url=http%3A%2F%2Fwww.youdidwhatwithtsql.com%2Fbeware-powershell-operator%2F1403' title="Beware the Powershell  Contains operator" alt=" Beware the Powershell  Contains operator" /></p><p>Post from: <a href="http://www.youdidwhatwithtsql.com">youdidwhatwithtsql.com</a><br/><br/><a href="http://www.youdidwhatwithtsql.com/beware-powershell-operator/1403">Beware the Powershell -Contains operator</a></p>
<div class="none"><div class="g-plusone" data-href="http://www.youdidwhatwithtsql.com/beware-powershell-operator/1403" size="standard" count="true"></div></div>]]></content:encoded>
			<wfw:commentRss>http://www.youdidwhatwithtsql.com/beware-powershell-operator/1403/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Monitoring SSRS Subscriptions with Powershell</title>
		<link>http://www.youdidwhatwithtsql.com/monitoring-ssrs-subscriptions-powershell/1392</link>
		<comments>http://www.youdidwhatwithtsql.com/monitoring-ssrs-subscriptions-powershell/1392#comments</comments>
		<pubDate>Fri, 25 Nov 2011 13:17:09 +0000</pubDate>
		<dc:creator>Rhys</dc:creator>
				<category><![CDATA[DBA]]></category>
		<category><![CDATA[Powershell]]></category>
		<category><![CDATA[SSRS]]></category>
		<category><![CDATA[Report Subscriptions]]></category>

		<guid isPermaLink="false">http://www.youdidwhatwithtsql.com/?p=1392</guid>
		<description><![CDATA[We don&#8217;t use SSRS much at my workplace but its usage is slowly creeping up. I realised that none of us are keeping an eye on the few subscriptions we have set-up. So I decided to do something about that. Here&#8217;s a bit of Powershell code that uses the SSRS Web Service to pull out [...]<p>Post from: <a href="http://www.youdidwhatwithtsql.com">youdidwhatwithtsql.com</a><br/><br/><a href="http://www.youdidwhatwithtsql.com/monitoring-ssrs-subscriptions-powershell/1392">Monitoring SSRS Subscriptions with Powershell</a></p>
]]></description>
			<content:encoded><![CDATA[<p>We don&#8217;t use <a title="SQL Server Reporting Services" href="http://msdn.microsoft.com/en-us/library/ms159106.aspx" target="_blank">SSRS </a>much at my workplace but its usage is slowly creeping up. I realised that none of us are keeping an eye on the few subscriptions we have set-up. So I decided to do something about that.</p>
<p>Here&#8217;s a bit of <a title="Windows Powershell" href="http://technet.microsoft.com/en-us/scriptcenter/dd742419" target="_blank">Powershell</a> code that uses the <a title="SSRS Web Service" href="http://msdn.microsoft.com/en-us/library/ms152787.aspx" target="_blank">SSRS Web Service</a> to pull out a list of subscriptions from SSRS and print out some information to the screen. As always I try to bring problems to attention with a little red text so you can identify any failed subscriptions. There&#8217;s a few assumptions in the script, so be sure to read the comments, and it&#8217;s a far from complete and fully tested script. Just a little something to get me started onto something better.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p1392code24'); return false;">View Code</a> POWERSHELL</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p139224"><td class="code" id="p1392code24"><pre class="powershell" style="font-family:monospace;"><span style="color: #008000;"># If you use multiple ssrs server just stick in another foreach loop</span>
<span style="color: #008000;"># and iterate over an array of ssrs server names.</span>
<span style="color: #800080;">$reportserver</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;sqlserver&quot;</span>;
<span style="color: #800080;">$url</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;http://$($reportserver)/reportserver/reportservice.asmx?WSDL&quot;</span>;
&nbsp;
<span style="color: #800080;">$ssrs</span> <span style="color: pink;">=</span> New<span style="color: pink;">-</span>WebServiceProxy <span style="color: pink;">-</span>uri <span style="color: #800080;">$url</span> <span style="color: pink;">-</span>UseDefaultCredential <span style="color: #008080; font-style: italic;">-Namespace</span> <span style="color: #800000;">&quot;ReportingWebService&quot;</span>;
&nbsp;
<span style="color: #008000;"># Uncomment to list all available methods &amp;amp; properties in the ssrs web service...</span>
<span style="color: #008000;">#$ssrs | Get-Member;</span>
&nbsp;
<span style="color: #008000;"># Get datasources (assumes default path to folder)</span>
<span style="color: #800080;">$datasources</span> <span style="color: pink;">=</span> <span style="color: #800080;">$ssrs</span>.ListChildren<span style="color: #000000;">&#40;</span><span style="color: #800000;">&quot;/Data Sources&quot;</span><span style="color: pink;">,</span> <span style="color: #800080;">$true</span><span style="color: #000000;">&#41;</span>;
&nbsp;
<span style="color: #008000;"># for each datasource</span>
<span style="color: #0000FF;">foreach</span><span style="color: #000000;">&#40;</span><span style="color: #800080;">$ds</span> <span style="color: #0000FF;">in</span> <span style="color: #800080;">$datasources</span><span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
	<span style="color: #008000;"># Get reports</span>
	<span style="color: #800080;">$reports</span> <span style="color: pink;">=</span> <span style="color: #800080;">$ssrs</span>.ListReportsUsingDataSource<span style="color: #000000;">&#40;</span><span style="color: #800080;">$ds</span>.Path<span style="color: #000000;">&#41;</span>;
	<span style="color: #008000;"># For each report</span>
	<span style="color: #0000FF;">foreach</span><span style="color: #000000;">&#40;</span><span style="color: #800080;">$r</span> <span style="color: #0000FF;">in</span> <span style="color: #800080;">$reports</span><span style="color: #000000;">&#41;</span>
	<span style="color: #000000;">&#123;</span>
		<span style="color: #008000;"># Get all subscriptions</span>
		<span style="color: #800080;">$subscriptions</span> <span style="color: pink;">=</span> <span style="color: #800080;">$ssrs</span>.ListSubscriptions<span style="color: #000000;">&#40;</span><span style="color: #800080;">$r</span>.Path<span style="color: pink;">,</span> <span style="color: #800080;">$r</span>.Owner<span style="color: #000000;">&#41;</span>;
		<span style="color: #008000;"># foreach subscription</span>
		<span style="color: #0000FF;">foreach</span><span style="color: #000000;">&#40;</span><span style="color: #800080;">$s</span> <span style="color: #0000FF;">in</span> <span style="color: #800080;">$subscriptions</span><span style="color: #000000;">&#41;</span>
		<span style="color: #000000;">&#123;</span>
			<span style="color: #008000;"># Uncomment to view more subscription methods &amp;amp; properties</span>
			<span style="color: #008000;"># $s | Get-Member;</span>
			<span style="color: #008000;"># Probably missing a few important keywords here...</span>
			<span style="color: #800080;">$colour</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;Green&quot;</span>;
			<span style="color: #0000FF;">if</span><span style="color: #000000;">&#40;</span><span style="color: #800080;">$s</span>.Status <span style="color: #FF0000;">-match</span> <span style="color: #800000;">&quot;Failure&quot;</span> <span style="color: #FF0000;">-or</span> <span style="color: #800080;">$s</span>.Status <span style="color: #FF0000;">-match</span> <span style="color: #800000;">&quot;Error&quot;</span><span style="color: #000000;">&#41;</span>
			<span style="color: #000000;">&#123;</span>
				<span style="color: #800080;">$colour</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;Red&quot;</span>;
			<span style="color: #000000;">&#125;</span>
			<span style="color: #008080; font-weight: bold;">Write-Host</span> <span style="color: #008080; font-style: italic;">-ForegroundColor</span> <span style="color: #800080;">$colour</span> <span style="color: #800080;">$s</span>.Report <span style="color: #800080;">$s</span>.Status <span style="color: #800080;">$s</span>.LastExecuted <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">Format-Table</span> <span style="color: #008080; font-style: italic;">-AutoSize</span>;
		<span style="color: #000000;">&#125;</span>
	<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p>After running this script successfully you should be something like below;</p>
<p><a href="http://www.youdidwhatwithtsql.com/monitoring-ssrs-subscriptions-powershell/1392/powershell_ssrs-2" rel="attachment wp-att-1399"><img class="alignnone size-full wp-image-1399" title="powershell ssrs" src="http://www.youdidwhatwithtsql.com/wp-content/uploads/2011/11/powershell_ssrs1.png" alt="powershell ssrs1 Monitoring SSRS Subscriptions with Powershell" width="677" height="342" /></a></p>
<p>&nbsp;</p>
<p><map name='google_ad_map_1392_a45beff5d2e172f6'>
<area shape='rect' href='http://imageads.googleadservices.com/pagead/imgclick/1392?pos=0' coords='1,2,367,28' />
<area shape='rect' href='http://services.google.com/feedback/abg' coords='384,10,453,23'/></map>
<img usemap='#google_ad_map_1392_a45beff5d2e172f6' border='0' src='http://imageads.googleadservices.com/pagead/ads?format=468x30_aff_img&amp;client=&amp;channel=&amp;output=png&amp;cuid=1392&amp;url=http%3A%2F%2Fwww.youdidwhatwithtsql.com%2Fmonitoring-ssrs-subscriptions-powershell%2F1392' title="Monitoring SSRS Subscriptions with Powershell" alt=" Monitoring SSRS Subscriptions with Powershell" /></p><p>Post from: <a href="http://www.youdidwhatwithtsql.com">youdidwhatwithtsql.com</a><br/><br/><a href="http://www.youdidwhatwithtsql.com/monitoring-ssrs-subscriptions-powershell/1392">Monitoring SSRS Subscriptions with Powershell</a></p>
<div class="none"><div class="g-plusone" data-href="http://www.youdidwhatwithtsql.com/monitoring-ssrs-subscriptions-powershell/1392" size="standard" count="true"></div></div>]]></content:encoded>
			<wfw:commentRss>http://www.youdidwhatwithtsql.com/monitoring-ssrs-subscriptions-powershell/1392/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Using Powershell to increment the computers date</title>
		<link>http://www.youdidwhatwithtsql.com/powershell-increment-computers-date/1389</link>
		<comments>http://www.youdidwhatwithtsql.com/powershell-increment-computers-date/1389#comments</comments>
		<pubDate>Thu, 10 Nov 2011 16:10:14 +0000</pubDate>
		<dc:creator>Rhys</dc:creator>
				<category><![CDATA[Powershell]]></category>

		<guid isPermaLink="false">http://www.youdidwhatwithtsql.com/?p=1389</guid>
		<description><![CDATA[Here&#8217;s a little snippet of Powershell code I used recently to test some TSQL that runs according to a two week schedule. This code will increment the date by one day, up to the maximum specified in $days, sleeping in between for a short while. The date is set back correctly at the end. Far [...]<p>Post from: <a href="http://www.youdidwhatwithtsql.com">youdidwhatwithtsql.com</a><br/><br/><a href="http://www.youdidwhatwithtsql.com/powershell-increment-computers-date/1389">Using Powershell to increment the computers date</a></p>
]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s a little snippet of <a title="Windows Powershell" href="http://en.wikipedia.org/wiki/Windows_PowerShell" target="_blank">Powershell</a> code I used recently to test some <a title="TSQL" href="http://en.wikipedia.org/wiki/Transact-SQL" target="_blank">TSQL</a> that runs according to a two week schedule.</p>
<p>This code will increment the date by one day, up to the maximum specified in <strong>$days</strong>, sleeping in between for a short while. The date is set back correctly at the end. Far from rocket science but it helps me test various bits of code in minutes instead of 2 weeks!</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p1389code26'); return false;">View Code</a> POWERSHELL</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p138926"><td class="code" id="p1389code26"><pre class="powershell" style="font-family:monospace;"><span style="color: #008000;"># Number of days to increment the date by</span>
<span style="color: #800080;">$days</span> <span style="color: pink;">=</span> <span style="color: #804000;">14</span>;
&nbsp;
<span style="color: #0000FF;">for</span><span style="color: #000000;">&#40;</span><span style="color: #800080;">$counter</span><span style="color: pink;">=</span><span style="color: #804000;">0</span>; <span style="color: #800080;">$counter</span> <span style="color: #FF0000;">-lt</span> <span style="color: #800080;">$days</span>; <span style="color: #800080;">$counter</span><span style="color: pink;">++</span><span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
	<span style="color: #008080; font-weight: bold;">Set-Date</span> <span style="color: #000000;">&#40;</span><span style="color: #008080; font-weight: bold;">Get-Date</span><span style="color: #000000;">&#41;</span>.AddDays<span style="color: #000000;">&#40;</span><span style="color: #804000;">1</span><span style="color: #000000;">&#41;</span>;
	<span style="color: #008000;"># Sleep for 2 minutes so the code gets a chance to run</span>
	<span style="color: #008080; font-weight: bold;">Start-Sleep</span> <span style="color: #008080; font-style: italic;">-Seconds</span> <span style="color: #804000;">120</span>;
<span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #008000;"># Set the date back correctly</span>
<span style="color: #008080; font-weight: bold;">Set-Date</span> <span style="color: #000000;">&#40;</span><span style="color: #008080; font-weight: bold;">Get-Date</span><span style="color: #000000;">&#41;</span>.AddDays<span style="color: #000000;">&#40;</span><span style="color: pink;">-</span><span style="color: #800080;">$days</span><span style="color: #000000;">&#41;</span>;</pre></td></tr></table></div>

<p><map name='google_ad_map_1389_a45beff5d2e172f6'>
<area shape='rect' href='http://imageads.googleadservices.com/pagead/imgclick/1389?pos=0' coords='1,2,367,28' />
<area shape='rect' href='http://services.google.com/feedback/abg' coords='384,10,453,23'/></map>
<img usemap='#google_ad_map_1389_a45beff5d2e172f6' border='0' src='http://imageads.googleadservices.com/pagead/ads?format=468x30_aff_img&amp;client=&amp;channel=&amp;output=png&amp;cuid=1389&amp;url=http%3A%2F%2Fwww.youdidwhatwithtsql.com%2Fpowershell-increment-computers-date%2F1389' title="Using Powershell to increment the computers date" alt=" Using Powershell to increment the computers date" /></p><p>Post from: <a href="http://www.youdidwhatwithtsql.com">youdidwhatwithtsql.com</a><br/><br/><a href="http://www.youdidwhatwithtsql.com/powershell-increment-computers-date/1389">Using Powershell to increment the computers date</a></p>
<div class="none"><div class="g-plusone" data-href="http://www.youdidwhatwithtsql.com/powershell-increment-computers-date/1389" size="standard" count="true"></div></div>]]></content:encoded>
			<wfw:commentRss>http://www.youdidwhatwithtsql.com/powershell-increment-computers-date/1389/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>TSQL to generate date lookup table data</title>
		<link>http://www.youdidwhatwithtsql.com/tsql-generate-date-lookup-table-data/1387</link>
		<comments>http://www.youdidwhatwithtsql.com/tsql-generate-date-lookup-table-data/1387#comments</comments>
		<pubDate>Thu, 10 Nov 2011 13:20:43 +0000</pubDate>
		<dc:creator>Rhys</dc:creator>
				<category><![CDATA[T-SQL]]></category>

		<guid isPermaLink="false">http://www.youdidwhatwithtsql.com/?p=1387</guid>
		<description><![CDATA[I needed to generate a range of data about dates for a lookup table. There&#8217;s an elegant solution using a recursive cte that does the job; ?View Code TSQLWITH daysCte &#40; d &#41; AS &#40; SELECT CONVERT&#40;DATETIME, '1 January 2011'&#41; AS d -- starting date UNION ALL SELECT DATEADD&#40;D, 1, d&#41; FROM daysCte WHERE DATEPART&#40;yyyy, d&#41; [...]<p>Post from: <a href="http://www.youdidwhatwithtsql.com">youdidwhatwithtsql.com</a><br/><br/><a href="http://www.youdidwhatwithtsql.com/tsql-generate-date-lookup-table-data/1387">TSQL to generate date lookup table data</a></p>
]]></description>
			<content:encoded><![CDATA[<p>I needed to generate a range of data about dates for a lookup table. There&#8217;s an elegant solution using a <a title="Recurive common table expression" href="http://msdn.microsoft.com/en-us/library/ms186243.aspx" target="_blank">recursive cte</a> that does the job;</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p1387code28'); return false;">View Code</a> TSQL</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p138728"><td class="code" id="p1387code28"><pre class="tsql" style="font-family:monospace;"><span style="color: #0000FF;">WITH</span> daysCte
<span style="color: #808080;">&#40;</span>
	d 
<span style="color: #808080;">&#41;</span>
<span style="color: #0000FF;">AS</span>
<span style="color: #808080;">&#40;</span>
	<span style="color: #0000FF;">SELECT</span> <span style="color: #0000FF;">CONVERT</span><span style="color: #808080;">&#40;</span><span style="color: #0000FF;">DATETIME</span>, <span style="color: #FF0000;">'1 January 2011'</span><span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span> d <span style="color: #008080;">-- starting date</span>
	<span style="color: #0000FF;">UNION</span> <span style="color: #808080;">ALL</span>
	<span style="color: #0000FF;">SELECT</span> <span style="color: #FF00FF;">DATEADD</span><span style="color: #808080;">&#40;</span>D, <span style="color: #000;">1</span>, d<span style="color: #808080;">&#41;</span>
	<span style="color: #0000FF;">FROM</span> daysCte
	<span style="color: #0000FF;">WHERE</span> <span style="color: #FF00FF;">DATEPART</span><span style="color: #808080;">&#40;</span>yyyy, d<span style="color: #808080;">&#41;</span> <span style="color: #808080;">&lt;=</span> <span style="color: #000;">2012</span> <span style="color: #008080;">-- stop year</span>
<span style="color: #808080;">&#41;</span>
<span style="color: #0000FF;">SELECT</span> d, 
	   <span style="color: #FF00FF;">DATEPART</span><span style="color: #808080;">&#40;</span>wk, d<span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span> week_number,
	   <span style="color: #FF00FF;">DATENAME</span><span style="color: #808080;">&#40;</span>dw, d<span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span> day_name,
	   <span style="color: #FF00FF;">DATENAME</span><span style="color: #808080;">&#40;</span>m, d<span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span> month_name,
	   <span style="color: #FF00FF;">DATENAME</span><span style="color: #808080;">&#40;</span>q, d<span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span> <span style="color: #808080;">&#91;</span>quarter<span style="color: #808080;">&#93;</span>
<span style="color: #0000FF;">FROM</span> daysCte 
<span style="color: #0000FF;">OPTION</span> <span style="color: #808080;">&#40;</span>MAXRECURSION <span style="color: #000;">800</span><span style="color: #808080;">&#41;</span>; <span style="color: #008080;">-- set &gt; number of days you want data for</span></pre></td></tr></table></div>

<p>This will display something looking like below;</p>
<pre>
d			week_number	day_name	month_name	quarter
2011-01-01 00:00:00.000	1		Saturday	January		1
2011-01-02 00:00:00.000	2		Sunday		January		1
2011-01-03 00:00:00.000	2		Monday		January		1
2011-01-04 00:00:00.000	2		Tuesday		January		1
2011-01-05 00:00:00.000	2		Wednesday	January		1
2011-01-06 00:00:00.000	2		Thursday	January		1
2011-01-07 00:00:00.000	2		Friday		January		1
</pre>
<p><map name='google_ad_map_1387_a45beff5d2e172f6'>
<area shape='rect' href='http://imageads.googleadservices.com/pagead/imgclick/1387?pos=0' coords='1,2,367,28' />
<area shape='rect' href='http://services.google.com/feedback/abg' coords='384,10,453,23'/></map>
<img usemap='#google_ad_map_1387_a45beff5d2e172f6' border='0' src='http://imageads.googleadservices.com/pagead/ads?format=468x30_aff_img&amp;client=&amp;channel=&amp;output=png&amp;cuid=1387&amp;url=http%3A%2F%2Fwww.youdidwhatwithtsql.com%2Ftsql-generate-date-lookup-table-data%2F1387' title="TSQL to generate date lookup table data" alt=" TSQL to generate date lookup table data" /></p><p>Post from: <a href="http://www.youdidwhatwithtsql.com">youdidwhatwithtsql.com</a><br/><br/><a href="http://www.youdidwhatwithtsql.com/tsql-generate-date-lookup-table-data/1387">TSQL to generate date lookup table data</a></p>
<div class="none"><div class="g-plusone" data-href="http://www.youdidwhatwithtsql.com/tsql-generate-date-lookup-table-data/1387" size="standard" count="true"></div></div>]]></content:encoded>
			<wfw:commentRss>http://www.youdidwhatwithtsql.com/tsql-generate-date-lookup-table-data/1387/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>MySQL Storage engine benchmarking</title>
		<link>http://www.youdidwhatwithtsql.com/mysql-storage-engine-benchmarking/1384</link>
		<comments>http://www.youdidwhatwithtsql.com/mysql-storage-engine-benchmarking/1384#comments</comments>
		<pubDate>Mon, 07 Nov 2011 20:49:37 +0000</pubDate>
		<dc:creator>Rhys</dc:creator>
				<category><![CDATA[DBA]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[Benchmark]]></category>
		<category><![CDATA[InnoDB]]></category>
		<category><![CDATA[MyISAM]]></category>

		<guid isPermaLink="false">http://www.youdidwhatwithtsql.com/mysql-storage-engine-benchmarking/1384</guid>
		<description><![CDATA[Here&#8217;s a stored procedure I use to perform some simple benchmarking of inserts for MySQL. It takes three parameters; p_table_type which should be set to the storage engine you wish to benchmark i.e. &#8216;MyISAM&#8217;, &#8216;InnoDB&#8217;, p_inserts; set this to the number of inserts to perform. p_autocommit; set the autocommit variable (relevant to InnoDB only) to [...]<p>Post from: <a href="http://www.youdidwhatwithtsql.com">youdidwhatwithtsql.com</a><br/><br/><a href="http://www.youdidwhatwithtsql.com/mysql-storage-engine-benchmarking/1384">MySQL Storage engine benchmarking</a></p>
]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s a stored procedure I use to perform some simple benchmarking of inserts for <a title="MySQL" href="http://dev.mysql.com" target="_blank">MySQL</a>. It takes three parameters; <strong>p_table_type</strong> which should be set to the storage engine you wish to benchmark i.e. &#8216;MyISAM&#8217;, &#8216;InnoDB&#8217;, <strong>p_inserts</strong>; set this to the number of inserts to perform. <strong>p_autocommit</strong>; set the <a title="InnoDB autocommit variable" href="http://dev.mysql.com/doc/refman/5.0/en/innodb-transaction-model.html" target="_blank">autocommit</a> variable (relevant to <a title="InnoDB Storage Engine" href="http://www.innodb.com/" target="_blank">InnoDB</a> only) to 0 or 1.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p1384code33'); return false;">View Code</a> MYSQL</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p138433"><td class="code" id="p1384code33"><pre class="mysql" style="font-family:monospace;">DELIMITER $$
<span style="color: #990099; font-weight: bold;">USE</span> <span style="color: #008000;">`test`</span>$$
<span style="color: #990099; font-weight: bold;">DROP</span> <span style="color: #990099; font-weight: bold;">PROCEDURE</span> <span style="color: #009900;">IF</span> <span style="color: #990099; font-weight: bold;">EXISTS</span> <span style="color: #008000;">`table<span style="color: #008080; font-weight: bold;">_</span>engine<span style="color: #008080; font-weight: bold;">_</span>test`</span>$$
        <span style="color: #990099; font-weight: bold;">CREATE</span> <span style="color: #990099; font-weight: bold;">DEFINER</span><span style="color: #CC0099;">=</span><span style="color: #008000;">`root`</span>@<span style="color: #008000;">`<span style="color: #008080; font-weight: bold;">%</span>`</span>
        <span style="color: #990099; font-weight: bold;">PROCEDURE</span> <span style="color: #008000;">`table<span style="color: #008080; font-weight: bold;">_</span>engine<span style="color: #008080; font-weight: bold;">_</span>test`</span><span style="color: #FF00FF;">&#40;</span><span style="color: #990099; font-weight: bold;">IN</span> p_table_type <span style="color: #999900; font-weight: bold;">VARCHAR</span><span style="color: #FF00FF;">&#40;</span><span style="color: #008080;">20</span><span style="color: #FF00FF;">&#41;</span><span style="color: #000033;">,</span>
                                      <span style="color: #990099; font-weight: bold;">IN</span> p_inserts    <span style="color: #999900; font-weight: bold;">INT</span><span style="color: #000033;">,</span>
                                      <span style="color: #990099; font-weight: bold;">IN</span> p_autocommit <span style="color: #999900; font-weight: bold;">TINYINT</span><span style="color: #FF00FF;">&#41;</span>
                <span style="color: #990099; font-weight: bold;">SQL SECURITY</span> <span style="color: #990099; font-weight: bold;">INVOKER</span>
        <span style="color: #990099; font-weight: bold;">BEGIN</span>
&nbsp;
                <span style="color: #990099; font-weight: bold;">DECLARE</span> sql_string <span style="color: #999900; font-weight: bold;">VARCHAR</span><span style="color: #FF00FF;">&#40;</span><span style="color: #008080;">300</span><span style="color: #FF00FF;">&#41;</span><span style="color: #000033;">;</span>
&nbsp;
                <span style="color: #808080; font-style: italic;"># Set session autocommit</span>
                <span style="color: #990099; font-weight: bold;">SET</span> <span style="color: #990099; font-weight: bold;">SESSION</span> autocommit <span style="color: #CC0099;">=</span> p_autocommit<span style="color: #000033;">;</span>
&nbsp;
                <span style="color: #808080; font-style: italic;"># TABLE TO hold session times</span>
                <span style="color: #990099; font-weight: bold;">CREATE</span> <span style="color: #990099; font-weight: bold;">TABLE</span> <span style="color: #990099; font-weight: bold;">IF <span style="color: #CC0099; font-weight: bold;">NOT</span> EXISTS</span> test_session
                             <span style="color: #FF00FF;">&#40;</span>
                                          Id         <span style="color: #999900; font-weight: bold;">INT</span> <span style="color: #CC0099; font-weight: bold;">NOT</span> <span style="color: #9900FF; font-weight: bold;">NULL</span> <span style="color: #990099; font-weight: bold;">PRIMARY KEY</span> <span style="color: #FF9900; font-weight: bold;">AUTO_INCREMENT</span><span style="color: #000033;">,</span>
                                          table_type <span style="color: #999900; font-weight: bold;">VARCHAR</span><span style="color: #FF00FF;">&#40;</span><span style="color: #008080;">20</span><span style="color: #FF00FF;">&#41;</span> <span style="color: #CC0099; font-weight: bold;">NOT</span> <span style="color: #9900FF; font-weight: bold;">NULL</span>                   <span style="color: #000033;">,</span>
                                          inserts <span style="color: #999900; font-weight: bold;">INT</span> <span style="color: #CC0099; font-weight: bold;">NOT</span> <span style="color: #9900FF; font-weight: bold;">NULL</span><span style="color: #000033;">,</span>
                                          autocommit <span style="color: #999900; font-weight: bold;">TINYINT</span> <span style="color: #CC0099; font-weight: bold;">NOT</span> <span style="color: #9900FF; font-weight: bold;">NULL</span><span style="color: #000033;">,</span>
                                          started    <span style="color: #999900; font-weight: bold;">DATETIME</span> <span style="color: #9900FF; font-weight: bold;">NULL</span>                          <span style="color: #000033;">,</span>
                                          finished   <span style="color: #999900; font-weight: bold;">DATETIME</span> <span style="color: #9900FF; font-weight: bold;">NULL</span>
                             <span style="color: #FF00FF;">&#41;</span><span style="color: #000033;">;</span>
&nbsp;
                <span style="color: #990099; font-weight: bold;">CREATE</span> <span style="color: #990099; font-weight: bold;">TABLE</span> <span style="color: #990099; font-weight: bold;">IF <span style="color: #CC0099; font-weight: bold;">NOT</span> EXISTS</span> test_session_inserts
                             <span style="color: #FF00FF;">&#40;</span>
                                          id              <span style="color: #999900; font-weight: bold;">INTEGER</span> <span style="color: #CC0099; font-weight: bold;">NOT</span> <span style="color: #9900FF; font-weight: bold;">NULL</span> <span style="color: #990099; font-weight: bold;">PRIMARY KEY</span> <span style="color: #FF9900; font-weight: bold;">AUTO_INCREMENT</span><span style="color: #000033;">,</span>
                                          test_session_id <span style="color: #999900; font-weight: bold;">INTEGER</span> <span style="color: #CC0099; font-weight: bold;">NOT</span> <span style="color: #9900FF; font-weight: bold;">NULL</span>                           <span style="color: #000033;">,</span>
                                          started         <span style="color: #999900; font-weight: bold;">DATETIME</span> <span style="color: #CC0099; font-weight: bold;">NOT</span> <span style="color: #9900FF; font-weight: bold;">NULL</span>                          <span style="color: #000033;">,</span>
                                          finished        <span style="color: #999900; font-weight: bold;">DATETIME</span> <span style="color: #CC0099; font-weight: bold;">NOT</span> <span style="color: #9900FF; font-weight: bold;">NULL</span>
                             <span style="color: #FF00FF;">&#41;</span><span style="color: #000033;">;</span>
&nbsp;
                <span style="color: #808080; font-style: italic;"># clean up ANY existing test TABLE</span>
                <span style="color: #990099; font-weight: bold;">DROP</span> <span style="color: #990099; font-weight: bold;">TABLE</span> <span style="color: #009900;">IF</span> <span style="color: #990099; font-weight: bold;">EXISTS</span> test_table_type<span style="color: #000033;">;</span>
&nbsp;
                <span style="color: #990099; font-weight: bold;">SET</span> sql_string <span style="color: #CC0099;">=</span> <span style="color: #000099;">CONCAT</span><span style="color: #FF00FF;">&#40;</span><span style="color: #008000;">'CREATE TABLE test<span style="color: #008080; font-weight: bold;">_</span>table<span style="color: #008080; font-weight: bold;">_</span>type
					(
						id INTEGER NOT NULL PRIMARY KEY AUTO<span style="color: #008080; font-weight: bold;">_</span>INCREMENT,
						random INTEGER,
						text1 VARCHAR(10) NOT NULL,
						text2 VARCHAR(10) NOT NULL
					)ENGINE = '</span><span style="color: #000033;">,</span> p_table_type<span style="color: #FF00FF;">&#41;</span><span style="color: #000033;">;</span>
                <span style="color: #808080; font-style: italic;"># PREPARE SQL AND EXECUTE</span>
                <span style="color: #990099; font-weight: bold;">SET</span> @q <span style="color: #CC0099;">=</span> sql_string<span style="color: #000033;">;</span>
                PREPARE stmt <span style="color: #990099; font-weight: bold;">FROM</span> @q<span style="color: #000033;">;</span>
                EXECUTE stmt<span style="color: #000033;">;</span>
                DEALLOCATE PREPARE stmt<span style="color: #000033;">;</span>
                <span style="color: #808080; font-style: italic;"># START the test session</span>
                <span style="color: #990099; font-weight: bold;">INSERT</span>
                <span style="color: #990099; font-weight: bold;">INTO</span>   test_session
                       <span style="color: #FF00FF;">&#40;</span>
                              table_type<span style="color: #000033;">,</span>
                              inserts<span style="color: #000033;">,</span>
                              autocommit<span style="color: #000033;">,</span>
                              started
                       <span style="color: #FF00FF;">&#41;</span>
                       <span style="color: #990099; font-weight: bold;">VALUES</span>
                       <span style="color: #FF00FF;">&#40;</span>
                              p_table_type<span style="color: #000033;">,</span>
                              p_inserts<span style="color: #000033;">,</span>
                              p_autocommit<span style="color: #000033;">,</span>
                              <span style="color: #000099;">NOW</span><span style="color: #FF00FF;">&#40;</span><span style="color: #FF00FF;">&#41;</span>
                       <span style="color: #FF00FF;">&#41;</span><span style="color: #000033;">;</span>
&nbsp;
                <span style="color: #990099; font-weight: bold;">SET</span> @id               <span style="color: #CC0099;">=</span> <span style="color: #000099;">LAST_INSERT_ID</span><span style="color: #FF00FF;">&#40;</span><span style="color: #FF00FF;">&#41;</span><span style="color: #000033;">;</span>
                <span style="color: #990099; font-weight: bold;">SET</span> @i                <span style="color: #CC0099;">=</span> <span style="color: #008080;">0</span><span style="color: #000033;">;</span>
                while_loop: WHILE <span style="color: #FF00FF;">&#40;</span>@i <span style="color: #CC0099;">&lt;</span> p_inserts<span style="color: #FF00FF;">&#41;</span> <span style="color: #990099; font-weight: bold;">DO</span>
                <span style="color: #808080; font-style: italic;"># Generate VALUES for insert</span>
                <span style="color: #990099; font-weight: bold;">SET</span> @random  <span style="color: #CC0099;">=</span> <span style="color: #000099;">RAND</span><span style="color: #FF00FF;">&#40;</span><span style="color: #FF00FF;">&#41;</span><span style="color: #000033;">;</span>
                <span style="color: #990099; font-weight: bold;">SET</span> @text1   <span style="color: #CC0099;">=</span> <span style="color: #000099;">SUBSTRING</span><span style="color: #FF00FF;">&#40;</span><span style="color: #000099;">MD5</span><span style="color: #FF00FF;">&#40;</span><span style="color: #000099;">RAND</span><span style="color: #FF00FF;">&#40;</span><span style="color: #FF00FF;">&#41;</span><span style="color: #FF00FF;">&#41;</span><span style="color: #000033;">,</span> <span style="color: #CC0099;">-</span><span style="color: #008080;">10</span><span style="color: #FF00FF;">&#41;</span><span style="color: #000033;">;</span>
                <span style="color: #990099; font-weight: bold;">SET</span> @text2   <span style="color: #CC0099;">=</span> <span style="color: #000099;">SUBSTRING</span><span style="color: #FF00FF;">&#40;</span><span style="color: #000099;">MD5</span><span style="color: #FF00FF;">&#40;</span><span style="color: #000099;">RAND</span><span style="color: #FF00FF;">&#40;</span><span style="color: #FF00FF;">&#41;</span><span style="color: #FF00FF;">&#41;</span><span style="color: #000033;">,</span> <span style="color: #CC0099;">-</span><span style="color: #008080;">10</span><span style="color: #FF00FF;">&#41;</span><span style="color: #000033;">;</span>
                <span style="color: #990099; font-weight: bold;">SET</span> @started <span style="color: #CC0099;">=</span> <span style="color: #000099;">NOW</span><span style="color: #FF00FF;">&#40;</span><span style="color: #FF00FF;">&#41;</span><span style="color: #000033;">;</span>
                <span style="color: #808080; font-style: italic;"># INSERT the test row</span>
                <span style="color: #990099; font-weight: bold;">INSERT</span>
                <span style="color: #990099; font-weight: bold;">INTO</span>   test_table_type
                       <span style="color: #FF00FF;">&#40;</span>
                              random<span style="color: #000033;">,</span>
                              text1 <span style="color: #000033;">,</span>
                              text2
                       <span style="color: #FF00FF;">&#41;</span>
                       <span style="color: #990099; font-weight: bold;">VALUES</span>
                       <span style="color: #FF00FF;">&#40;</span>
                              @random<span style="color: #000033;">,</span>
                              @text1 <span style="color: #000033;">,</span>
                              @text2
                       <span style="color: #FF00FF;">&#41;</span><span style="color: #000033;">;</span>
&nbsp;
                <span style="color: #808080; font-style: italic;"># record INSERT times</span>
                        <span style="color: #990099; font-weight: bold;">INSERT</span>
                        <span style="color: #990099; font-weight: bold;">INTO</span>   test_session_inserts
                               <span style="color: #FF00FF;">&#40;</span>
                                      test_session_id<span style="color: #000033;">,</span>
                                      started        <span style="color: #000033;">,</span>
                                      finished
                               <span style="color: #FF00FF;">&#41;</span>
                               <span style="color: #990099; font-weight: bold;">VALUES</span>
                               <span style="color: #FF00FF;">&#40;</span>
                                      @id     <span style="color: #000033;">,</span>
                                      @started<span style="color: #000033;">,</span>
                                      <span style="color: #000099;">NOW</span><span style="color: #FF00FF;">&#40;</span><span style="color: #FF00FF;">&#41;</span>
                               <span style="color: #FF00FF;">&#41;</span><span style="color: #000033;">;</span>
&nbsp;
                        <span style="color: #808080; font-style: italic;"># increment counter</span>
                        <span style="color: #990099; font-weight: bold;">SET</span> @i <span style="color: #CC0099;">=</span> @i <span style="color: #CC0099;">+</span> <span style="color: #008080;">1</span><span style="color: #000033;">;</span>
                <span style="color: #009900;">END</span> WHILE while_loop<span style="color: #000033;">;</span>
                <span style="color: #808080; font-style: italic;"># Finish the session</span>
                <span style="color: #990099; font-weight: bold;">UPDATE</span> test_session
                <span style="color: #990099; font-weight: bold;">SET</span>    finished <span style="color: #CC0099;">=</span> <span style="color: #000099;">NOW</span><span style="color: #FF00FF;">&#40;</span><span style="color: #FF00FF;">&#41;</span>
                <span style="color: #990099; font-weight: bold;">WHERE</span>  id       <span style="color: #CC0099;">=</span> @id<span style="color: #000033;">;</span>
&nbsp;
<span style="color: #009900;">END</span>$$
DELIMITER <span style="color: #000033;">;</span></pre></td></tr></table></div>

<p>Run your tests like so&#8230;</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p1384code34'); return false;">View Code</a> MYSQL</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p138434"><td class="code" id="p1384code34"><pre class="mysql" style="font-family:monospace;"><span style="color: #990099; font-weight: bold;">CALL</span> table_engine_test<span style="color: #FF00FF;">&#40;</span><span style="color: #008000;">'MyISAM'</span><span style="color: #000033;">,</span> <span style="color: #008080;">10000</span><span style="color: #000033;">,</span> <span style="color: #008080;">0</span><span style="color: #FF00FF;">&#41;</span><span style="color: #000033;">;</span>
<span style="color: #990099; font-weight: bold;">CALL</span> table_engine_test<span style="color: #FF00FF;">&#40;</span><span style="color: #008000;">'InnoDB'</span><span style="color: #000033;">,</span> <span style="color: #008080;">10000</span><span style="color: #000033;">,</span> <span style="color: #008080;">0</span><span style="color: #FF00FF;">&#41;</span><span style="color: #000033;">;</span>
<span style="color: #990099; font-weight: bold;">CALL</span> table_engine_test<span style="color: #FF00FF;">&#40;</span><span style="color: #008000;">'InnoDB'</span><span style="color: #000033;">,</span> <span style="color: #008080;">10000</span><span style="color: #000033;">,</span> <span style="color: #008080;">1</span><span style="color: #FF00FF;">&#41;</span><span style="color: #000033;">;</span>
<span style="color: #990099; font-weight: bold;">CALL</span> table_engine_test<span style="color: #FF00FF;">&#40;</span><span style="color: #008000;">'MyISAM'</span><span style="color: #000033;">,</span> <span style="color: #008080;">100000</span><span style="color: #000033;">,</span> <span style="color: #008080;">0</span><span style="color: #FF00FF;">&#41;</span><span style="color: #000033;">;</span>
<span style="color: #990099; font-weight: bold;">CALL</span> table_engine_test<span style="color: #FF00FF;">&#40;</span><span style="color: #008000;">'InnoDB'</span><span style="color: #000033;">,</span> <span style="color: #008080;">100000</span><span style="color: #000033;">,</span> <span style="color: #008080;">0</span><span style="color: #FF00FF;">&#41;</span><span style="color: #000033;">;</span>
<span style="color: #990099; font-weight: bold;">CALL</span> table_engine_test<span style="color: #FF00FF;">&#40;</span><span style="color: #008000;">'InnoDB'</span><span style="color: #000033;">,</span> <span style="color: #008080;">100000</span><span style="color: #000033;">,</span> <span style="color: #008080;">1</span><span style="color: #FF00FF;">&#41;</span><span style="color: #000033;">;</span></pre></td></tr></table></div>

<p>The <strong>test_session</strong> contains some summary information about each of the tests;</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p1384code35'); return false;">View Code</a> MYSQL</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p138435"><td class="code" id="p1384code35"><pre class="mysql" style="font-family:monospace;"><span style="color: #990099; font-weight: bold;">SELECT</span> <span style="color: #CC0099;">*</span>
<span style="color: #990099; font-weight: bold;">FROM</span> test_session<span style="color: #000033;">;</span></pre></td></tr></table></div>

<p><a href="http://www.youdidwhatwithtsql.com/wp-content/uploads/2011/11/mysql_table_engine_test.png"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;" title="mysql_table_engine_test" src="http://www.youdidwhatwithtsql.com/wp-content/uploads/2011/11/mysql_table_engine_test_thumb.png" alt="mysql table engine test thumb MySQL Storage engine benchmarking" width="644" height="166" border="0" /></a></p>
<p>Calculate the time taken for each test with the following query;</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p1384code36'); return false;">View Code</a> MYSQL</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p138436"><td class="code" id="p1384code36"><pre class="mysql" style="font-family:monospace;"><span style="color: #990099; font-weight: bold;">SELECT</span> <span style="color: #CC0099;">*</span><span style="color: #000033;">,</span> TIMEDIFF<span style="color: #FF00FF;">&#40;</span>finished<span style="color: #000033;">,</span> started<span style="color: #FF00FF;">&#41;</span> <span style="color: #990099; font-weight: bold;">AS</span> seconds
<span style="color: #990099; font-weight: bold;">FROM</span> test_session<span style="color: #000033;">;</span></pre></td></tr></table></div>

<p>Happy Benchmarking!</p>
<p><map name='google_ad_map_1384_a45beff5d2e172f6'>
<area shape='rect' href='http://imageads.googleadservices.com/pagead/imgclick/1384?pos=0' coords='1,2,367,28' />
<area shape='rect' href='http://services.google.com/feedback/abg' coords='384,10,453,23'/></map>
<img usemap='#google_ad_map_1384_a45beff5d2e172f6' border='0' src='http://imageads.googleadservices.com/pagead/ads?format=468x30_aff_img&amp;client=&amp;channel=&amp;output=png&amp;cuid=1384&amp;url=http%3A%2F%2Fwww.youdidwhatwithtsql.com%2Fmysql-storage-engine-benchmarking%2F1384' title="MySQL Storage engine benchmarking" alt=" MySQL Storage engine benchmarking" /></p><p>Post from: <a href="http://www.youdidwhatwithtsql.com">youdidwhatwithtsql.com</a><br/><br/><a href="http://www.youdidwhatwithtsql.com/mysql-storage-engine-benchmarking/1384">MySQL Storage engine benchmarking</a></p>
<div class="none"><div class="g-plusone" data-href="http://www.youdidwhatwithtsql.com/mysql-storage-engine-benchmarking/1384" size="standard" count="true"></div></div>]]></content:encoded>
			<wfw:commentRss>http://www.youdidwhatwithtsql.com/mysql-storage-engine-benchmarking/1384/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Testing a Failover Cluster with Powershell</title>
		<link>http://www.youdidwhatwithtsql.com/testing-failover-cluster-powershell/1377</link>
		<comments>http://www.youdidwhatwithtsql.com/testing-failover-cluster-powershell/1377#comments</comments>
		<pubDate>Thu, 03 Nov 2011 11:26:22 +0000</pubDate>
		<dc:creator>Rhys</dc:creator>
				<category><![CDATA[DBA]]></category>
		<category><![CDATA[Powershell]]></category>
		<category><![CDATA[failover cluster]]></category>

		<guid isPermaLink="false">http://www.youdidwhatwithtsql.com/?p=1377</guid>
		<description><![CDATA[Just a quick Powershell snippet that I&#8217;m going to use to run validation tests on one of my staging Failover Clusters during OOH. The script below will take some services offline, run the validation tests, before bringing the appropriate cluster groups back online. The report will be saved using the date as the name. To [...]<p>Post from: <a href="http://www.youdidwhatwithtsql.com">youdidwhatwithtsql.com</a><br/><br/><a href="http://www.youdidwhatwithtsql.com/testing-failover-cluster-powershell/1377">Testing a Failover Cluster with Powershell</a></p>
]]></description>
			<content:encoded><![CDATA[<p>Just a quick <a title="Windows Powershell" href="http://en.wikipedia.org/wiki/Windows_PowerShell" target="_blank">Powershell</a> snippet that I&#8217;m going to use to run validation tests on one of my staging Failover Clusters during OOH.</p>
<p>The script below will take some services offline, run the validation tests, before bringing the appropriate cluster groups back online. The report will be saved using the date as the name. To use this you will need to set <strong>$cluster</strong> appropriately and perhaps customize the cluster groups that are brought offline &amp; online.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p1377code38'); return false;">View Code</a> POWERSHELL</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p137738"><td class="code" id="p1377code38"><pre class="powershell" style="font-family:monospace;">Import<span style="color: pink;">-</span>Module FailoverClusters;
&nbsp;
<span style="color: #008000;"># Set cluster name</span>
<span style="color: #800080;">$cluster</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;Cluster&quot;</span>;
&nbsp;
<span style="color: #008000;"># Date stamp used for report name</span>
<span style="color: #800080;">$date</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">Get-Date</span> <span style="color: #008080; font-style: italic;">-Format</span> <span style="color: #800000;">&quot;yyyyMMdd&quot;</span>;
&nbsp;
<span style="color: #008000;"># Take cluster services offline. You may need to customise this</span>
<span style="color: #008000;"># according to your specific needs</span>
Stop<span style="color: pink;">-</span>ClusterGroup <span style="color: pink;">-</span>Cluster <span style="color: #800080;">$cluster</span> <span style="color: #008080; font-style: italic;">-Name</span> <span style="color: #800000;">&quot;ClusterDtc&quot;</span>;
Stop<span style="color: pink;">-</span>ClusterGroup <span style="color: pink;">-</span>Cluster <span style="color: #800080;">$cluster</span> <span style="color: #008080; font-style: italic;">-Name</span> <span style="color: #800000;">&quot;SQL Server (MSSQLSERVER)&quot;</span>;
&nbsp;
<span style="color: #008000;"># Test Cluster</span>
Test<span style="color: pink;">-</span>Cluster <span style="color: pink;">-</span>Cluster <span style="color: #800080;">$cluster</span> <span style="color: pink;">-</span>ReportName <span style="color: #800000;">&quot;$date&quot;</span>;
&nbsp;
<span style="color: #008000;"># Bring services back online</span>
Start<span style="color: pink;">-</span>ClusterGroup <span style="color: pink;">-</span>Cluster <span style="color: #800080;">$cluster</span> <span style="color: #008080; font-style: italic;">-Name</span> <span style="color: #800000;">&quot;ClusterDtc&quot;</span>;
Start<span style="color: pink;">-</span>ClusterGroup <span style="color: pink;">-</span>Cluster <span style="color: #800080;">$cluster</span> <span style="color: #008080; font-style: italic;">-Name</span> <span style="color: #800000;">&quot;SQL Server (MSSQLSERVER)&quot;</span>;</pre></td></tr></table></div>

<p>The output will look something like below&#8230;</p>
<pre>Name                       OwnerNode                                      State
----                       ---------                                      -----
ClusterDtc            	   Node1                                 	  Offline
SQL Server (MSSQLSERVER)   Node1                                 	  Offline
WARNING: Cluster Configuration - Validate Resource Status: The test reported
some warnings..
WARNING: Network - Validate IP Configuration: The test reported some warnings..
WARNING:
Test Result:
ClusterConditionallyApproved
Testing has completed successfully. The configuration appears to be suitable
for clustering.  However, you should review the report because it may contain
warnings which you should address to attain the highest availability.
Test report file path: C:\Users\ClusterAdmin\AppData\Local\Temp\20111103.mht
20111103.mht
ClusterDtc            	   Node1                                 	 Online
SQL Server (MSSQLSERVER)   Node1                                 	 Online</pre>
<p><map name='google_ad_map_1377_a45beff5d2e172f6'>
<area shape='rect' href='http://imageads.googleadservices.com/pagead/imgclick/1377?pos=0' coords='1,2,367,28' />
<area shape='rect' href='http://services.google.com/feedback/abg' coords='384,10,453,23'/></map>
<img usemap='#google_ad_map_1377_a45beff5d2e172f6' border='0' src='http://imageads.googleadservices.com/pagead/ads?format=468x30_aff_img&amp;client=&amp;channel=&amp;output=png&amp;cuid=1377&amp;url=http%3A%2F%2Fwww.youdidwhatwithtsql.com%2Ftesting-failover-cluster-powershell%2F1377' title="Testing a Failover Cluster with Powershell" alt=" Testing a Failover Cluster with Powershell" /></p><p>Post from: <a href="http://www.youdidwhatwithtsql.com">youdidwhatwithtsql.com</a><br/><br/><a href="http://www.youdidwhatwithtsql.com/testing-failover-cluster-powershell/1377">Testing a Failover Cluster with Powershell</a></p>
<div class="none"><div class="g-plusone" data-href="http://www.youdidwhatwithtsql.com/testing-failover-cluster-powershell/1377" size="standard" count="true"></div></div>]]></content:encoded>
			<wfw:commentRss>http://www.youdidwhatwithtsql.com/testing-failover-cluster-powershell/1377/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

<!-- Dynamic page generated in 6.666 seconds. -->
<!-- Cached page generated by WP-Super-Cache on 2012-02-05 22:03:17 -->

