<?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 &#187; Powershell</title>
	<atom:link href="http://www.youdidwhatwithtsql.com/tag/powershell/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>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('p1403code7'); return false;">View Code</a> POWERSHELL</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p14037"><td class="code" id="p1403code7"><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('p1403code8'); return false;">View Code</a> POWERSHELL</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p14038"><td class="code" id="p1403code8"><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('p1403code9'); return false;">View Code</a> POWERSHELL</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p14039"><td class="code" id="p1403code9"><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('p1403code10'); return false;">View Code</a> POWERSHELL</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p140310"><td class="code" id="p1403code10"><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('p1392code12'); return false;">View Code</a> POWERSHELL</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p139212"><td class="code" id="p1392code12"><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>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('p1377code14'); return false;">View Code</a> POWERSHELL</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p137714"><td class="code" id="p1377code14"><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>
		<item>
		<title>Domain user password expiry with Powershell</title>
		<link>http://www.youdidwhatwithtsql.com/domain-user-password-expiry-powershell/1372</link>
		<comments>http://www.youdidwhatwithtsql.com/domain-user-password-expiry-powershell/1372#comments</comments>
		<pubDate>Thu, 13 Oct 2011 11:14:17 +0000</pubDate>
		<dc:creator>Rhys</dc:creator>
				<category><![CDATA[Powershell]]></category>
		<category><![CDATA[Password expiry]]></category>

		<guid isPermaLink="false">http://www.youdidwhatwithtsql.com/?p=1372</guid>
		<description><![CDATA[I needed to figure out a method for producing alerts when a domain account is approaching the password reset date. Here it is in a few lines of Powershell&#8230; ?View Code POWERSHELL# Set name here $name = &#34;Rhys Campbell&#34;; $user = Get-ADUser -LDAPFilter &#34;(Name=$name)&#34; -Properties PasswordLastSet; $days = $&#40;Get-ADDefaultDomainPasswordPolicy&#41;.MaxPasswordAge; $expires = $user.PasswordLastSet + $days; $days_left [...]<p>Post from: <a href="http://www.youdidwhatwithtsql.com">youdidwhatwithtsql.com</a><br/><br/><a href="http://www.youdidwhatwithtsql.com/domain-user-password-expiry-powershell/1372">Domain user password expiry with Powershell</a></p>
]]></description>
			<content:encoded><![CDATA[<p>I needed to figure out a method for producing alerts when a domain account is approaching the password reset date. Here it is in a few lines of Powershell&#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('p1372code16'); return false;">View Code</a> POWERSHELL</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p137216"><td class="code" id="p1372code16"><pre class="powershell" style="font-family:monospace;"><span style="color: #008000;"># Set name here</span>
<span style="color: #800080;">$name</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;Rhys Campbell&quot;</span>;
<span style="color: #800080;">$user</span> <span style="color: pink;">=</span> Get<span style="color: pink;">-</span>ADUser <span style="color: pink;">-</span>LDAPFilter <span style="color: #800000;">&quot;(Name=$name)&quot;</span> <span style="color: pink;">-</span>Properties PasswordLastSet;
<span style="color: #800080;">$days</span> <span style="color: pink;">=</span> $<span style="color: #000000;">&#40;</span>Get<span style="color: pink;">-</span>ADDefaultDomainPasswordPolicy<span style="color: #000000;">&#41;</span>.MaxPasswordAge;
<span style="color: #800080;">$expires</span> <span style="color: pink;">=</span> <span style="color: #800080;">$user</span>.PasswordLastSet <span style="color: pink;">+</span> <span style="color: #800080;">$days</span>;
<span style="color: #800080;">$days_left</span> <span style="color: pink;">=</span> <span style="color: #800080;">$expires</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>;
<span style="color: #008080; font-weight: bold;">Write-Host</span> <span style="color: #800000;">&quot;Password for $name expires on $expires which is in $($days_left.Days) days.&quot;</span>;</pre></td></tr></table></div>

<p>This will display something along the lines of;</p>
<pre>Password for Rhys Campbell expires on 11/18/2011 08:19:36 which is in 35 days.</pre>
<p><map name='google_ad_map_1372_a45beff5d2e172f6'>
<area shape='rect' href='http://imageads.googleadservices.com/pagead/imgclick/1372?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_1372_a45beff5d2e172f6' border='0' src='http://imageads.googleadservices.com/pagead/ads?format=468x30_aff_img&amp;client=&amp;channel=&amp;output=png&amp;cuid=1372&amp;url=http%3A%2F%2Fwww.youdidwhatwithtsql.com%2Fdomain-user-password-expiry-powershell%2F1372' title="Domain user password expiry with Powershell" alt=" Domain user password expiry with Powershell" /></p><p>Post from: <a href="http://www.youdidwhatwithtsql.com">youdidwhatwithtsql.com</a><br/><br/><a href="http://www.youdidwhatwithtsql.com/domain-user-password-expiry-powershell/1372">Domain user password expiry with Powershell</a></p>
<div class="none"><div class="g-plusone" data-href="http://www.youdidwhatwithtsql.com/domain-user-password-expiry-powershell/1372" size="standard" count="true"></div></div>]]></content:encoded>
			<wfw:commentRss>http://www.youdidwhatwithtsql.com/domain-user-password-expiry-powershell/1372/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Checking Disk alignment with Powershell</title>
		<link>http://www.youdidwhatwithtsql.com/checking-disk-alignment-with-powershell/1362</link>
		<comments>http://www.youdidwhatwithtsql.com/checking-disk-alignment-with-powershell/1362#comments</comments>
		<pubDate>Wed, 05 Oct 2011 19:36:04 +0000</pubDate>
		<dc:creator>Rhys</dc:creator>
				<category><![CDATA[DBA]]></category>
		<category><![CDATA[Powershell]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[disk alignment]]></category>
		<category><![CDATA[DISKPART]]></category>
		<category><![CDATA[StartingOffset]]></category>

		<guid isPermaLink="false">http://www.youdidwhatwithtsql.com/checking-disk-alignment-with-powershell/1362</guid>
		<description><![CDATA[Disk alignment has been well discussed on the web and the methods to check this always seem to use wmic or DISKPART. I&#8217;ve always loathed wmi so here&#8217;s a few lines of Powershell that achieves the same thing; ?View Code POWERSHELL$sqlserver = &#34;sqlinstance&#34;; # Get disk partitions $partitions = Get-WmiObject -ComputerName $sqlserver -Class Win32_DiskPartition; $partitions [...]<p>Post from: <a href="http://www.youdidwhatwithtsql.com">youdidwhatwithtsql.com</a><br/><br/><a href="http://www.youdidwhatwithtsql.com/checking-disk-alignment-with-powershell/1362">Checking Disk alignment with Powershell</a></p>
]]></description>
			<content:encoded><![CDATA[<p><a href="http://itknowledgeexchange.techtarget.com/sql-server/how-much-performance-are-you-loosing-by-not-aligning-your-drives/">Disk alignment</a> has been well discussed on the web and the methods to check this always seem to use <a title="wmic and DISKPART for disgn alignment" href="http://sqlskills.com/BLOGS/PAUL/post/Using-diskpart-to-check-disk-partition-alignment.aspx">wmic or DISKPART</a>. I&#8217;ve always loathed wmi so here&#8217;s a few lines of Powershell that achieves the same thing;</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('p1362code18'); return false;">View Code</a> POWERSHELL</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p136218"><td class="code" id="p1362code18"><pre class="powershell" style="font-family:monospace;"><span style="color: #800080;">$sqlserver</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;sqlinstance&quot;</span>;
<span style="color: #008000;"># Get disk partitions</span>
<span style="color: #800080;">$partitions</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">Get-WmiObject</span> <span style="color: #008080; font-style: italic;">-ComputerName</span> <span style="color: #800080;">$sqlserver</span> <span style="color: #008080; font-style: italic;">-Class</span> Win32_DiskPartition;
<span style="color: #800080;">$partitions</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> DeviceId<span style="color: pink;">,</span> Name<span style="color: pink;">,</span> Description<span style="color: pink;">,</span> BootPartition<span style="color: pink;">,</span> PrimaryPartition<span style="color: pink;">,</span> Index<span style="color: pink;">,</span> Size<span style="color: pink;">,</span> BlockSize<span style="color: pink;">,</span> StartingOffset <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 something looking like below;</p>
<pre>DeviceId              Name                  Description             BootPartition PrimaryPartition Index          Size BlockSize StartingOffset
--------              ----                  -----------             ------------- ---------------- -----          ---- --------- --------------
Disk #2, Partition #0 Disk #2, Partition #0 Installable File System         False             True     0 1099523162112       512        1048576
Disk #3, Partition #0 Disk #3, Partition #0 Installable File System         False             True     0  536878252032       512        1048576
Disk #4, Partition #0 Disk #4, Partition #0 Installable File System         False             True     0    1082130432       512          65536
Disk #5, Partition #0 Disk #5, Partition #0 Installable File System         False             True     0    1082130432       512          65536
Disk #1, Partition #0 Disk #1, Partition #0 Installable File System         False             True     0  107376279552       512        1048576
Disk #0, Partition #0 Disk #0, Partition #0 Installable File System          True             True     0     104857600       512        1048576
Disk #0, Partition #1 Disk #0, Partition #1 Installable File System         False             True     1   81684070400       512      105906176
Disk #0, Partition #2 Disk #0, Partition #2 Installable File System         False             True     2  104857600000       512    81789976576
Disk #0, Partition #3 Disk #0, Partition #3 Installable File System         False             True     3  104857600000       512   186647576576</pre>
<p>A <a href="http://msdn.microsoft.com/en-us/library/dd758814(v=sql.100).aspx">64K cluster size</a> is good for SQL Server. But what about the offset? The simple calculation below can be used to check this&#8230;</p>
<p><strong>StartingOffset / BlockSize / 128 </strong>(a 64K cluster has 128 sectors assuming a 512 block size).</p>
<p>If this calculation spits out a number with any decimal places then you have some disk aligning to do.</p>
<p><strong><font color="#666666"></font></strong></p>
<p><map name='google_ad_map_1362_a45beff5d2e172f6'>
<area shape='rect' href='http://imageads.googleadservices.com/pagead/imgclick/1362?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_1362_a45beff5d2e172f6' border='0' src='http://imageads.googleadservices.com/pagead/ads?format=468x30_aff_img&amp;client=&amp;channel=&amp;output=png&amp;cuid=1362&amp;url=http%3A%2F%2Fwww.youdidwhatwithtsql.com%2Fchecking-disk-alignment-with-powershell%2F1362' title="Checking Disk alignment with Powershell" alt=" Checking Disk alignment with Powershell" /></p><p>Post from: <a href="http://www.youdidwhatwithtsql.com">youdidwhatwithtsql.com</a><br/><br/><a href="http://www.youdidwhatwithtsql.com/checking-disk-alignment-with-powershell/1362">Checking Disk alignment with Powershell</a></p>
<div class="none"><div class="g-plusone" data-href="http://www.youdidwhatwithtsql.com/checking-disk-alignment-with-powershell/1362" size="standard" count="true"></div></div>]]></content:encoded>
			<wfw:commentRss>http://www.youdidwhatwithtsql.com/checking-disk-alignment-with-powershell/1362/feed</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Fun with the Get-Hotfix cmdlet</title>
		<link>http://www.youdidwhatwithtsql.com/fun-with-the-get-hotfix-cmdlet/1334</link>
		<comments>http://www.youdidwhatwithtsql.com/fun-with-the-get-hotfix-cmdlet/1334#comments</comments>
		<pubDate>Mon, 15 Aug 2011 11:37:00 +0000</pubDate>
		<dc:creator>Rhys</dc:creator>
				<category><![CDATA[Powershell]]></category>
		<category><![CDATA[Hotfix]]></category>

		<guid isPermaLink="false">http://www.youdidwhatwithtsql.com/fun-with-the-get-hotfix-cmdlet/1334</guid>
		<description><![CDATA[With the Get-Hotfix cmdlet you can query the list of hotfixes that have been applied to computers. ?View Code POWERSHELLGet-Hotfix &#124; Format-Table -AutoSize; This will display the list of hotfixes installed on the local computer. Source Description HotFixID InstalledBy InstalledOn ------ ----------- -------- ----------- ----------- SO0590 Update 982861 NT AUTHORITY\SYSTEM 07/07/2011 00:00:00 SO0590 Update KB958830 [...]<p>Post from: <a href="http://www.youdidwhatwithtsql.com">youdidwhatwithtsql.com</a><br/><br/><a href="http://www.youdidwhatwithtsql.com/fun-with-the-get-hotfix-cmdlet/1334">Fun with the Get-Hotfix cmdlet</a></p>
]]></description>
			<content:encoded><![CDATA[<p>With the <a title="Get-Hotfix Powershell cmdlet" href="http://technet.microsoft.com/en-us/library/dd315358.aspx" target="_blank">Get-Hotfix</a> cmdlet you can query the list of hotfixes that have been applied to computers.</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('p1334code21'); return false;">View Code</a> POWERSHELL</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p133421"><td class="code" id="p1334code21"><pre class="powershell" style="font-family:monospace;">Get<span style="color: pink;">-</span>Hotfix <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 the list of hotfixes installed on the local computer.</p>
<pre>Source Description     HotFixID  InstalledBy          InstalledOn
------ -----------     --------  -----------          -----------
SO0590 Update          982861    NT AUTHORITY\SYSTEM  07/07/2011 00:00:00
SO0590 Update          KB958830  host\Administrator   07/07/2011 00:00:00
SO0590 Update          KB958830  host\Administrator
SO0590 Update          KB971033  host\Administrator
SO0590 Update          KB2264107 NT AUTHORITY\SYSTEM  06/08/2011 00:00:00
SO0590 Security Update KB2305420 host\Administrator   03/10/2011 00:00:00
SO0590 Security Update KB2393802 host\Administrator   03/10/2011 00:00:00
SO0590 Security Update KB2425227 host\Administrator   03/10/2011 00:00:00
SO0590 Security Update KB2475792 host\Administrator   03/10/2011 00:00:00
SO0590 Security Update KB2476490 NT AUTHORITY\SYSTEM
SO0590 Security Update KB2479628 host\Administrator   03/10/2011 00:00:00
SO0590 Security Update KB2479943 host\Administrator   03/10/2011 00:00:00
SO0590 Update          KB2484033 host\Administrator   03/10/2011 00:00:00
SO0590 Security Update KB2485376 host\Administrator   03/10/2011 00:00:00
SO0590 Update          KB2487426 host\Administrator   03/10/2011 00:00:00
SO0590 Update          KB2488113 NT AUTHORITY\SYSTEM  06/09/2011 00:00:00
SO0590 Security Update KB2491683 NT AUTHORITY\SYSTEM  06/09/2011 00:00:00
SO0590 Update          KB2492386 NT AUTHORITY\SYSTEM  06/09/2011 00:00:00</pre>
<p>Not overly impressive in itself but <a title="Windows Powershell" href="http://en.wikipedia.org/wiki/Windows_PowerShell" target="_blank">Powershell</a> really comes into its own when querying multiple computers. For example you may wish to confirm that a bunch of computers all have an important hotfix installed. This script will do it. Just alter the <strong>$HotFixID</strong> and <strong>$computers</strong> as needed.</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('p1334code22'); return false;">View Code</a> POWERSHELL</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p133422"><td class="code" id="p1334code22"><pre class="powershell" style="font-family:monospace;"><span style="color: #008000;"># HotFixId to check for</span>
<span style="color: #800080;">$HotFixID</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;KB958830&quot;</span>;
&nbsp;
<span style="color: #008000;"># Array of computers to check</span>
<span style="color: #800080;">$computers</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: pink;">,</span> <span style="color: #800000;">&quot;server4&quot;</span><span style="color: pink;">,</span> <span style="color: #800000;">&quot;server5&quot;</span><span style="color: #000000;">&#41;</span>;
&nbsp;
<span style="color: #008000;"># Query each computer</span>
<span style="color: #0000FF;">foreach</span><span style="color: #000000;">&#40;</span><span style="color: #800080;">$computer</span> <span style="color: #0000FF;">in</span> <span style="color: #800080;">$computers</span><span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
	<span style="color: #800080;">$hf</span> <span style="color: pink;">=</span> Get<span style="color: pink;">-</span>HotFix <span style="color: #008080; font-style: italic;">-ComputerName</span> <span style="color: #800080;">$computer</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>.HotFixId <span style="color: #FF0000;">-eq</span> <span style="color: #800080;">$HotFixID</span><span style="color: #000000;">&#125;</span> <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">Select-Object</span> <span style="color: #008080; font-style: italic;">-First</span> <span style="color: #804000;">1</span>;
	<span style="color: #0000FF;">if</span><span style="color: #000000;">&#40;</span><span style="color: #800080;">$hf</span> <span style="color: #FF0000;">-eq</span> <span style="color: #800080;">$null</span><span style="color: #000000;">&#41;</span>
	<span style="color: #000000;">&#123;</span>
		<span style="color: #008080; font-weight: bold;">Write-Host</span> <span style="color: #800000;">&quot;Hotfix $HotFixID is not installed on $computer&quot;</span>;
	<span style="color: #000000;">&#125;</span>
	<span style="color: #0000FF;">else</span>
	<span style="color: #000000;">&#123;</span>
		<span style="color: #008080; font-weight: bold;">Write-Host</span> <span style="color: #800000;">&quot;Hotfix $HotFixID was installed on $computer on by &quot;</span> $<span style="color: #000000;">&#40;</span><span style="color: #800080;">$hf</span>.InstalledBy<span style="color: #000000;">&#41;</span>;
	<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p>In a few moments you can see which computers you need to take action on;</p>
<pre>
Hotfix KB958830 was installed on server1 on by  SMARTODDS\campbellr
Hotfix KB958830 was installed on server2 on by  SMARTODDS\campbellr
Hotfix KB958830 is not installed on server3
Hotfix KB958830 is not installed on server4
Hotfix KB958830 is not installed on server5
</pre>
<p>Powershell; the eliminator of tedium!</p>
<p><map name='google_ad_map_1334_a45beff5d2e172f6'>
<area shape='rect' href='http://imageads.googleadservices.com/pagead/imgclick/1334?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_1334_a45beff5d2e172f6' border='0' src='http://imageads.googleadservices.com/pagead/ads?format=468x30_aff_img&amp;client=&amp;channel=&amp;output=png&amp;cuid=1334&amp;url=http%3A%2F%2Fwww.youdidwhatwithtsql.com%2Ffun-with-the-get-hotfix-cmdlet%2F1334' title="Fun with the Get Hotfix cmdlet" alt=" Fun with the Get Hotfix cmdlet" /></p><p>Post from: <a href="http://www.youdidwhatwithtsql.com">youdidwhatwithtsql.com</a><br/><br/><a href="http://www.youdidwhatwithtsql.com/fun-with-the-get-hotfix-cmdlet/1334">Fun with the Get-Hotfix cmdlet</a></p>
<div class="none"><div class="g-plusone" data-href="http://www.youdidwhatwithtsql.com/fun-with-the-get-hotfix-cmdlet/1334" size="standard" count="true"></div></div>]]></content:encoded>
			<wfw:commentRss>http://www.youdidwhatwithtsql.com/fun-with-the-get-hotfix-cmdlet/1334/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Fun with the Get-EventLog cmdlet</title>
		<link>http://www.youdidwhatwithtsql.com/fun-with-the-get-eventlog-cmdlet/1318</link>
		<comments>http://www.youdidwhatwithtsql.com/fun-with-the-get-eventlog-cmdlet/1318#comments</comments>
		<pubDate>Fri, 12 Aug 2011 11:22:00 +0000</pubDate>
		<dc:creator>Rhys</dc:creator>
				<category><![CDATA[Powershell]]></category>

		<guid isPermaLink="false">http://www.youdidwhatwithtsql.com/fun-with-the-get-eventlog-cmdlet/1318</guid>
		<description><![CDATA[The Get-EventLog cmdlet is great for working with the Windows Event Logs on local and remote computers. It includes lots of parameters that make life much easier than using the Event Viewer GUI. To list the available logs on the local computer just execute; ?View Code POWERSHELLGet-EventLog -List &#124; Format-Table -AutoSize; Max(K) Retain OverflowAction Entries [...]<p>Post from: <a href="http://www.youdidwhatwithtsql.com">youdidwhatwithtsql.com</a><br/><br/><a href="http://www.youdidwhatwithtsql.com/fun-with-the-get-eventlog-cmdlet/1318">Fun with the Get-EventLog cmdlet</a></p>
]]></description>
			<content:encoded><![CDATA[<p>The <a title="Powershell Get-EventLog cmdlet" href="http://technet.microsoft.com/en-us/library/dd315250.aspx" target="_blank">Get-EventLog cmdlet</a> is great for working with the Windows Event Logs on local and remote computers. It includes lots of parameters that make life much easier than using the Event Viewer GUI. </p>
<p>To list the available logs on the local computer just execute;</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('p1318code26'); return false;">View Code</a> POWERSHELL</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p131826"><td class="code" id="p1318code26"><pre class="powershell" style="font-family:monospace;"><span style="color: #008080; font-weight: bold;">Get-EventLog</span> <span style="color: #008080; font-style: italic;">-List</span> <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>

<pre>Max(K) Retain OverflowAction    Entries Log
------ ------ --------------    ------- ---
20,480      0 OverwriteAsNeeded  50,916 Application
20,480      0 OverwriteAsNeeded       0 HardwareEvents
   512      7 OverwriteOlder          0 Internet Explorer
20,480      0 OverwriteAsNeeded       0 Key Management Service
 8,192      0 OverwriteAsNeeded      52 Media Center
   128      0 OverwriteAsNeeded       3 OAlerts
                                        Security
20,480      0 OverwriteAsNeeded  56,258 System
15,360      0 OverwriteAsNeeded   2,889 Windows PowerShell</pre>
<p>It&#8217;s great for drilling down into the Event Logs to get the information you&#8217;re most interested in. For example, this line of Powershell gets all Errors in the Application Event Log, from the last 24 hours.</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('p1318code27'); return false;">View Code</a> POWERSHELL</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p131827"><td class="code" id="p1318code27"><pre class="powershell" style="font-family:monospace;"><span style="color: #008080; font-weight: bold;">Get-EventLog</span> <span style="color: #008080; font-style: italic;">-LogName</span> Application <span style="color: pink;">-</span>EntryType Error <span style="color: pink;">-</span>After $<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: #804000;">24</span><span style="color: #000000;">&#41;</span> <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 snippet can pull out all the Event Log errors from any combination of servers and logs within the last 24 hours. Great for those morning checks!</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('p1318code28'); return false;">View Code</a> POWERSHELL</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p131828"><td class="code" id="p1318code28"><pre class="powershell" style="font-family:monospace;"><span style="color: #008000;"># Set servers to query</span>
<span style="color: #800080;">$servers</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;server2&quot;</span><span style="color: #000000;">&#41;</span>;
<span style="color: #008000;"># Set event logs to query</span>
<span style="color: #800080;">$logs</span> <span style="color: pink;">=</span> <span style="color: pink;">@</span><span style="color: #000000;">&#40;</span><span style="color: #800000;">&quot;System&quot;</span><span style="color: pink;">,</span> <span style="color: #800000;">&quot;Application&quot;</span><span style="color: #000000;">&#41;</span>;
&nbsp;
<span style="color: #008080; font-weight: bold;">Write-Host</span> <span style="color: #800000;">&quot;Querying servers for event log errors in the last 24 hours...&quot;</span>;
<span style="color: #008080; font-weight: bold;">Write-Host</span> <span style="color: #800000;">&quot;&quot;</span>;
&nbsp;
<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;">$servers</span><span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</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: #008080; font-weight: bold;">Write-Host</span> <span style="color: #800000;">&quot;&quot;</span>;
	<span style="color: #0000FF;">foreach</span><span style="color: #000000;">&#40;</span><span style="color: #800080;">$log</span> <span style="color: #0000FF;">in</span> <span style="color: #800080;">$logs</span><span style="color: #000000;">&#41;</span>
	<span style="color: #000000;">&#123;</span>
		<span style="color: #008080; font-weight: bold;">Write-Host</span> <span style="color: #800000;">&quot;$log Event Log&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: #800080;">$log</span> <span style="color: pink;">-</span>EntryType Error <span style="color: pink;">-</span>After $<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: #804000;">24</span><span style="color: #000000;">&#41;</span> <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></pre></td></tr></table></div>

<pre>Querying servers for event log errors in the last 24 hours...

server1
====================================

System Event Log
=================

Index Time         EntryType Source                  InstanceID Message
----- ----         --------- ------                  ---------- -------
80222 Jul 26 19:56 Error     Service Control Manager 3221232472 The VMware vCenter Converter Standalone Worker service...
80221 Jul 26 19:56 Error     Service Control Manager 3221232481 A timeout was reached (30000 milliseconds) while waiti...
80220 Jul 26 19:55 Error     Service Control Manager 3221232472 The VMware vCenter Converter Standalone Server service...
80219 Jul 26 19:55 Error     Service Control Manager 3221232481 A timeout was reached (30000 milliseconds) while waiti...
80202 Jul 26 19:55 Error     Service Control Manager 3221232481 A timeout was reached (30000 milliseconds) while waiti...

Application Event Log
=================

Index Time         EntryType Source   InstanceID Message
----- ----         --------- ------   ---------- -------
90050 Jul 26 19:56 Error     VzCdbSvc          7 Failed to load the plug-in module. (GUID = {56F9312C-C989-4E04-8C23-2...
90048 Jul 26 19:56 Error     VzCdbSvc          7 Failed to load the plug-in module. (GUID = {48512A59-C8A5-4805-9048-2...

server2
====================================

System Event Log
=================

Index Time         EntryType Source                  InstanceID Message
----- ----         --------- ------                  ---------- -------
80222 Jul 26 19:56 Error     Service Control Manager 3221232472 The VMware vCenter Converter Standalone Worker service...
80221 Jul 26 19:56 Error     Service Control Manager 3221232481 A timeout was reached (30000 milliseconds) while waiti...
80220 Jul 26 19:55 Error     Service Control Manager 3221232472 The VMware vCenter Converter Standalone Server service...
80219 Jul 26 19:55 Error     Service Control Manager 3221232481 A timeout was reached (30000 milliseconds) while waiti...
80202 Jul 26 19:55 Error     Service Control Manager 3221232481 A timeout was reached (30000 milliseconds) while waiti...

Application Event Log
=================

Index Time         EntryType Source   InstanceID Message
----- ----         --------- ------   ---------- -------
90050 Jul 26 19:56 Error     VzCdbSvc          7 Failed to load the plug-in module. (GUID = {56F9312C-C989-4E04-8C23-2...
90048 Jul 26 19:56 Error     VzCdbSvc          7 Failed to load the plug-in module. (GUID = {48512A59-C8A5-4805-9048-2...

server3
====================================

System Event Log
=================

Index Time         EntryType Source                  InstanceID Message
----- ----         --------- ------                  ---------- -------
80222 Jul 26 19:56 Error     Service Control Manager 3221232472 The VMware vCenter Converter Standalone Worker service...
80221 Jul 26 19:56 Error     Service Control Manager 3221232481 A timeout was reached (30000 milliseconds) while waiti...
80220 Jul 26 19:55 Error     Service Control Manager 3221232472 The VMware vCenter Converter Standalone Server service...
80219 Jul 26 19:55 Error     Service Control Manager 3221232481 A timeout was reached (30000 milliseconds) while waiti...
80202 Jul 26 19:55 Error     Service Control Manager 3221232481 A timeout was reached (30000 milliseconds) while waiti...

Application Event Log
=================

Index Time         EntryType Source   InstanceID Message
----- ----         --------- ------   ---------- -------
90050 Jul 26 19:56 Error     VzCdbSvc          7 Failed to load the plug-in module. (GUID = {56F9312C-C989-4E04-8C23-2...
90048 Jul 26 19:56 Error     VzCdbSvc          7 Failed to load the plug-in module. (GUID = {48512A59-C8A5-4805-9048-2...
</pre>
<p>The GUI is dead, long live Powershell!</p>
</pre>
<p><map name='google_ad_map_1318_a45beff5d2e172f6'>
<area shape='rect' href='http://imageads.googleadservices.com/pagead/imgclick/1318?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_1318_a45beff5d2e172f6' border='0' src='http://imageads.googleadservices.com/pagead/ads?format=468x30_aff_img&amp;client=&amp;channel=&amp;output=png&amp;cuid=1318&amp;url=http%3A%2F%2Fwww.youdidwhatwithtsql.com%2Ffun-with-the-get-eventlog-cmdlet%2F1318' title="Fun with the Get EventLog cmdlet" alt=" Fun with the Get EventLog cmdlet" /></p><p>Post from: <a href="http://www.youdidwhatwithtsql.com">youdidwhatwithtsql.com</a><br/><br/><a href="http://www.youdidwhatwithtsql.com/fun-with-the-get-eventlog-cmdlet/1318">Fun with the Get-EventLog cmdlet</a></p>
<div class="none"><div class="g-plusone" data-href="http://www.youdidwhatwithtsql.com/fun-with-the-get-eventlog-cmdlet/1318" size="standard" count="true"></div></div>]]></content:encoded>
			<wfw:commentRss>http://www.youdidwhatwithtsql.com/fun-with-the-get-eventlog-cmdlet/1318/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Identify the Active Cluster Node with Powershell</title>
		<link>http://www.youdidwhatwithtsql.com/identify-active-cluster-node-powershell/1315</link>
		<comments>http://www.youdidwhatwithtsql.com/identify-active-cluster-node-powershell/1315#comments</comments>
		<pubDate>Tue, 26 Jul 2011 13:24:26 +0000</pubDate>
		<dc:creator>Rhys</dc:creator>
				<category><![CDATA[DBA]]></category>
		<category><![CDATA[Powershell]]></category>
		<category><![CDATA[Failover Clustering]]></category>

		<guid isPermaLink="false">http://www.youdidwhatwithtsql.com/?p=1315</guid>
		<description><![CDATA[I wanted to find a way of programatically identifying the active node of a SQL Server Cluster. I found this post that demonstrated how to do it with TSQL. As I love Powershell so much here&#8217;s another method to do it; ?View Code POWERSHELL# Set cluster name $cluster_name = &#34;ClusterName&#34;; # Load SMO extension &#91;System.Reflection.Assembly&#93;::LoadWithPartialName&#40;&#34;Microsoft.SqlServer.Smo&#34;&#41; [...]<p>Post from: <a href="http://www.youdidwhatwithtsql.com">youdidwhatwithtsql.com</a><br/><br/><a href="http://www.youdidwhatwithtsql.com/identify-active-cluster-node-powershell/1315">Identify the Active Cluster Node with Powershell</a></p>
]]></description>
			<content:encoded><![CDATA[<p>I wanted to find a way of programatically identifying the active node of a SQL Server Cluster. I found this post that demonstrated <a href="http://sql.richarddouglas.co.uk/archive/2010/03/identifying-the-active-cluster-node.html" target="_blank">how to do it with TSQL</a>. As I love <a title="Windows Powershell" href="http://en.wikipedia.org/wiki/Windows_PowerShell" target="_blank">Powershell</a> so much here&#8217;s another method to 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('p1315code30'); return false;">View Code</a> POWERSHELL</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p131530"><td class="code" id="p1315code30"><pre class="powershell" style="font-family:monospace;"><span style="color: #008000;"># Set cluster name </span>
<span style="color: #800080;">$cluster_name</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;ClusterName&quot;</span>;
<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>;
<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;">$cluster_name</span>;
<span style="color: #008000;"># Get server properties</span>
<span style="color: #800080;">$properties</span> <span style="color: pink;">=</span> <span style="color: #800080;">$srv</span>.Properties
<span style="color: #800080;">$owner_node</span> <span style="color: pink;">=</span> <span style="color: #800080;">$properties</span>.Item<span style="color: #000000;">&#40;</span><span style="color: #800000;">&quot;ComputerNamePhysicalNetBIOS&quot;</span><span style="color: #000000;">&#41;</span>.Value;
<span style="color: #800080;">$is_clustered</span> <span style="color: pink;">=</span> <span style="color: #800080;">$properties</span>.Item<span style="color: #000000;">&#40;</span><span style="color: #800000;">&quot;IsClustered&quot;</span><span style="color: #000000;">&#41;</span>.Value
<span style="color: #0000FF;">if</span><span style="color: #000000;">&#40;</span><span style="color: #800080;">$is_clustered</span><span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
	<span style="color: #008080; font-weight: bold;">Write-Host</span> <span style="color: #800000;">&quot;The current active node of $cluster_name is $owner_node.&quot;</span>;
<span style="color: #000000;">&#125;</span>
<span style="color: #0000FF;">else</span>
<span style="color: #000000;">&#123;</span>
	<span style="color: #008080; font-weight: bold;">Write-Host</span> <span style="color: #800000;">&quot;$cluster_name is not a clustered instance of SQL Server.&quot;</span>;
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p>Execute against your cluster and it will tell you which is the current active node.</p>
<pre>The current active node of ClusterName is Node1.</pre>
<p>It will also tell you if the instance you&#8217;re executing against isn&#8217;t a cluster.</p>
<pre>NotACluster is not a clustered instance of SQL Server.</pre>
<p><map name='google_ad_map_1315_a45beff5d2e172f6'>
<area shape='rect' href='http://imageads.googleadservices.com/pagead/imgclick/1315?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_1315_a45beff5d2e172f6' border='0' src='http://imageads.googleadservices.com/pagead/ads?format=468x30_aff_img&amp;client=&amp;channel=&amp;output=png&amp;cuid=1315&amp;url=http%3A%2F%2Fwww.youdidwhatwithtsql.com%2Fidentify-active-cluster-node-powershell%2F1315' title="Identify the Active Cluster Node with Powershell" alt=" Identify the Active Cluster Node with Powershell" /></p><p>Post from: <a href="http://www.youdidwhatwithtsql.com">youdidwhatwithtsql.com</a><br/><br/><a href="http://www.youdidwhatwithtsql.com/identify-active-cluster-node-powershell/1315">Identify the Active Cluster Node with Powershell</a></p>
<div class="none"><div class="g-plusone" data-href="http://www.youdidwhatwithtsql.com/identify-active-cluster-node-powershell/1315" size="standard" count="true"></div></div>]]></content:encoded>
			<wfw:commentRss>http://www.youdidwhatwithtsql.com/identify-active-cluster-node-powershell/1315/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Failover All Cluster Resources With Powershell</title>
		<link>http://www.youdidwhatwithtsql.com/failover-cluster-resources-powershell/1309</link>
		<comments>http://www.youdidwhatwithtsql.com/failover-cluster-resources-powershell/1309#comments</comments>
		<pubDate>Fri, 22 Jul 2011 12:03:45 +0000</pubDate>
		<dc:creator>Rhys</dc:creator>
				<category><![CDATA[Powershell]]></category>
		<category><![CDATA[Failover Clustering]]></category>

		<guid isPermaLink="false">http://www.youdidwhatwithtsql.com/?p=1309</guid>
		<description><![CDATA[Here&#8217;s a simple example showing how to manage the failover process with Powershell, making sure all resources are running on one node. First, execute the below command to show which node owns the resources. ?View Code POWERSHELLGet-ClusterGroup -Cluster ClusterName &#124; Format-Table -AutoSize; Name OwnerNode State ---- --------- ----- SoStagSQL20Dtc Node1 Online SQL Server Node1 Online [...]<p>Post from: <a href="http://www.youdidwhatwithtsql.com">youdidwhatwithtsql.com</a><br/><br/><a href="http://www.youdidwhatwithtsql.com/failover-cluster-resources-powershell/1309">Failover All Cluster Resources With Powershell</a></p>
]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s a simple example showing how to manage the <a title="Windows Failover Clustering" href="http://www.microsoft.com/windowsserver2008/en/us/failover-clustering-main.aspx" target="_blank">failover</a> process with <a title="Windows Powershell" href="http://en.wikipedia.org/wiki/Windows_PowerShell" target="_blank">Powershell</a>, making sure all resources are running on one node. First, execute the below command to show which node owns the resources.</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('p1309code34'); return false;">View Code</a> POWERSHELL</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p130934"><td class="code" id="p1309code34"><pre class="powershell" style="font-family:monospace;">Get<span style="color: pink;">-</span>ClusterGroup <span style="color: pink;">-</span>Cluster ClusterName <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>

<pre>Name              OwnerNode     State
----              ---------     -----
SoStagSQL20Dtc    Node1 	Online
SQL Server        Node1 	Online
Cluster Group     Node1 	Online
Available Storage Node1 	Online</pre>
<p>In this example all services are currently running on Node1. It&#8217;s a simple <a title="Windows Powershell" href="http://en.wikipedia.org/wiki/Windows_PowerShell" target="_blank">Powershell</a> one-liner to failover everything to another node. The following example assumes a 2 node cluster and all services will be failed over to the other node;</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('p1309code35'); return false;">View Code</a> POWERSHELL</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p130935"><td class="code" id="p1309code35"><pre class="powershell" style="font-family:monospace;">Get<span style="color: pink;">-</span>ClusterNode <span style="color: pink;">-</span>Cluster ClusterName <span style="color: #008080; font-style: italic;">-Name</span> Node1 <span style="color: pink;">|</span> Get<span style="color: pink;">-</span>ClusterGroup <span style="color: pink;">|</span> Move<span style="color: pink;">-</span>ClusterGroup <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>All services are now running on Node2</p>
<pre>Name			OwnerNode	State
----			---------	-----
SoStagSQL20Dtc		Node2		Online
SQL Server		Node2		Online
Cluster Group		Node2		Online
Available Storage	Node2		Online</pre>
<p>If you have more than 2 nodes in the cluster you can use the -Name parameter of the <a title="Windows Powershell Move-ClusterGroup cmdlet" href="http://technet.microsoft.com/en-us/library/ee461002.aspx" target="_blank">Move-ClusterGroup</a> to specify a node to move resources to.</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('p1309code36'); return false;">View Code</a> POWERSHELL</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p130936"><td class="code" id="p1309code36"><pre class="powershell" style="font-family:monospace;">Get<span style="color: pink;">-</span>ClusterNode <span style="color: pink;">-</span>Cluster ClusterName <span style="color: #008080; font-style: italic;">-Name</span> Node1 <span style="color: pink;">|</span> Get<span style="color: pink;">-</span>ClusterGroup <span style="color: pink;">|</span> Move<span style="color: pink;">-</span>ClusterGroup <span style="color: #008080; font-style: italic;">-Name</span> Node2 <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>You may also like</p>
<p><a title="Powershell For Failover Clustering" href="http://www.youdidwhatwithtsql.com/powershell-for-failover-clustering/1060" target="_blank">Powershell for Failover Clustering</a><br />
<a title="Unable to start Cluster Service on one Node" href="http://www.youdidwhatwithtsql.com/unable-to-start-cluster-service-on-one-node/1066" target="_blank">Unable to start Cluster Service on one Node</a><br />
<a title="Cluster Network 'SAN1' is Partitioned" href="http://www.youdidwhatwithtsql.com/cluster-network-san1-is-partitioned/1288" target="_blank">Cluster Network &#8216;SAN1&#8242; is Partitioned</a></p>
<p><map name='google_ad_map_1309_a45beff5d2e172f6'>
<area shape='rect' href='http://imageads.googleadservices.com/pagead/imgclick/1309?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_1309_a45beff5d2e172f6' border='0' src='http://imageads.googleadservices.com/pagead/ads?format=468x30_aff_img&amp;client=&amp;channel=&amp;output=png&amp;cuid=1309&amp;url=http%3A%2F%2Fwww.youdidwhatwithtsql.com%2Ffailover-cluster-resources-powershell%2F1309' title="Failover All Cluster Resources With Powershell" alt=" Failover All Cluster Resources With Powershell" /></p><p>Post from: <a href="http://www.youdidwhatwithtsql.com">youdidwhatwithtsql.com</a><br/><br/><a href="http://www.youdidwhatwithtsql.com/failover-cluster-resources-powershell/1309">Failover All Cluster Resources With Powershell</a></p>
<div class="none"><div class="g-plusone" data-href="http://www.youdidwhatwithtsql.com/failover-cluster-resources-powershell/1309" size="standard" count="true"></div></div>]]></content:encoded>
			<wfw:commentRss>http://www.youdidwhatwithtsql.com/failover-cluster-resources-powershell/1309/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

