Automating Always On Configuration with PowerShell

If you are continually creating Always On availability groups you may want to speed up the enabling of the Always On service within SQL Configuration manager (see below). In my demo of a four node cluster creation from scratch, you “really” don’t want to manually log onto each node to reconfigure and restart the service!

Here is the PowerShell Script I use in a demo to enable multiple nodes at once

<!-- wp:preformatted -->
<pre class="wp-block-preformatted"># ConfigureAlwasyOn.ps1</pre>
<!-- /wp:preformatted -->

<!-- wp:preformatted -->
<pre class="wp-block-preformatted">#</pre>
<!-- /wp:preformatted -->

<!-- wp:preformatted -->
<pre class="wp-block-preformatted">#   SUMMARY;</pre>
<!-- /wp:preformatted -->

<!-- wp:preformatted -->
<pre class="wp-block-preformatted">#       Enables AlwaysOn on instances See </pre>
<!-- /wp:preformatted -->

<!-- wp:preformatted -->
<pre class="wp-block-preformatted"># http://msdn.microsoft.com/en-us/library/ff878259(v=sql.110).aspx</pre>
<!-- /wp:preformatted -->

<!-- wp:preformatted -->
<pre class="wp-block-preformatted">cd SQLSERVER:\SQL\NODE2\DEFAULT</pre>
<!-- /wp:preformatted -->

<!-- wp:preformatted -->
<pre class="wp-block-preformatted">Write-Host -ForegroundColor Green "Enabling AlwaysOn on NODE2"</pre>
<!-- /wp:preformatted -->

<!-- wp:preformatted -->
<pre class="wp-block-preformatted">Enable-SqlAlwaysOn -Force &gt; $null</pre>
<!-- /wp:preformatted -->

<!-- wp:preformatted -->
<pre class="wp-block-preformatted">cd SQLSERVER:\SQL\NODE3\DEFAULT</pre>
<!-- /wp:preformatted -->

<!-- wp:preformatted -->
<pre class="wp-block-preformatted">Write-Host -ForegroundColor Green "Enabling AlwaysOn on NODE3"</pre>
<!-- /wp:preformatted -->

<!-- wp:preformatted -->
<pre class="wp-block-preformatted">Enable-SqlAlwaysOn -Force &gt; $null</pre>
<!-- /wp:preformatted -->

<!-- wp:preformatted -->
<pre class="wp-block-preformatted">cd SQLSERVER:\SQL\NODE4\DEFAULT</pre>
<!-- /wp:preformatted -->

<!-- wp:preformatted -->
<pre class="wp-block-preformatted">Write-Host -ForegroundColor Green "Enabling AlwaysOn on NODE4"</pre>
<!-- /wp:preformatted -->

<!-- wp:preformatted -->
<pre class="wp-block-preformatted">Enable-SqlAlwaysOn -Force &gt; $null</pre>
<!-- /wp:preformatted -->

Notice that between RC0 and RTM of SQL 2012 the name of the cmdlet has changed from “-HaDrService” to “-SqlAlwaysOn”.The techies managed to catch up with the marketing people!

Leave a Reply