Book Image

SQL Server 2014 with PowerShell v5 Cookbook

By : Donabel Santos
Book Image

SQL Server 2014 with PowerShell v5 Cookbook

By: Donabel Santos

Overview of this book

Table of Contents (21 chapters)
SQL Server 2014 with PowerShell v5 Cookbook
Credits
About the Author
Acknowledgments
About the Reviewers
www.PacktPub.com
Preface
Index

Enabling AlwaysOn in SQL Server


In this recipe, we will enable the AlwaysOn feature in SQL Server.

Getting ready

Check whether the AlwaysOn feature is enabled. You can do this from the GUI by launching SQL Server Configuration Manager, right-clicking on the SQL Server database engine service, and selecting Properties. Click on the AlwaysOn High Availability tab:

You can also do this using PowerShell by running the following code:

$instanceName = "SQL01"
$server = New-Object Microsoft.SqlServer.Management.Smo.Server -ArgumentList $instanceName

#check AlwaysOn
$server.IsHadrEnabled

To check this feature against multiple nodes, you can use the following code snippet:

$nodeNames = Get-ClusterNode |
             Select-Object –ExpandProperty Name
Foreach-Object ($instanceName in $nodeNames) {
   $server = New-Object Microsoft.SqlServer.Management.Smo.Server -ArgumentList $instanceName

   #check AlwaysOn
   $server.IsHadrEnabled
}

How to do it...

Perform the following steps to enable AlwaysOn in SQL...