Enable-SqlAlwaysOn

Enables the AlwaysOn Availability Groups feature on the instance of SQL Server specified by the Path, InputObject,or ServerInstance parameter.
Enable-SqlAlwaysOn [[-Path] <string>] [-Credential <PSCredential>] [-Force] [-NoServiceRestart] [-Confirm][-WhatIf] [<CommonParameters>]
Enable-SqlAlwaysOn -InputObject* <Server> [-Credential <PSCredential>] [-Force] [-NoServiceRestart] [-Confirm][-WhatIf] [<CommonParameters>]
Enable-SqlAlwaysOn [-ServerInstance*] <string> [-Credential <PSCredential>] [-Force] [-NoServiceRestart] [-Confirm][-WhatIf] [<CommonParameters>]

The Enable-SqlAlwaysOn cmdlet enables AlwaysOn on an instance of SQL Server. If AlwaysOn Availability Groups is enabled while the SQL Server service is running, the Database Engine service must be restarted for the changes to complete. Unless you specify the -Force parameter, the cmdlet prompts you to ask whether you wish to restart the service; if cancelled, no operation occurs.

If AlwaysOn Availability Groups is already enabled, this cmdlet does nothing.

This cmdlet can run against a remote service. You must have Administrator permissions to execute this cmdlet.

Parameters
-Credential <PSCredential>

The name of the instance of SQL Server on which you want to enable AlwaysOn. The format should be MACHINENAMEINSTANCE. Can be used in conjunction with the -Credential parameter to change the AlwaysOn setting on a remote server.

-Force [<SwitchParameter>]

Specify -Force to compel the cmdlet to continue without any confirmation from to the user. This parameter is provided to permit the construction of scripts.

-InputObject <Server>

  • This value is required
  • Accepts pipeline input ByValue

The Server object of the instance of SQL Server where the AlwaysOn Availability Groups setting should be enabled.

-NoServiceRestart [<SwitchParameter>]

  • Default value is False

The user is not prompted to restart the SQL Server service. You must manually restart the SQL Server service for changes to take effect. When this parameter is set, -Force is ignored.

-Path <string>

The path to the instance of SQL Server. This is an optional parameter. If not specified, the value of this parameter defaults to the current working location.

-ServerInstance <string>

  • This value is required

The name of the instance of SQL Server where AlwaysOn is to be enabled. The format should be MACHINENAMEINSTANCE. Can be used with the -Credential parameter to change the AlwaysOn setting on a remote server.

-Confirm [<SwitchParameter>]

Prompts you for confirmation before executing the command.

-WhatIf [<SwitchParameter>]

Describes what would happen if you executed the command without actually executing the command.

<CommonParameters>

This cmdlet supports the common parameters: Verbose, Debug,ErrorAction, ErrorVariable, WarningAction, WarningVariable,OutBuffer, PipelineVariable, and OutVariable.

Inputs

A SMO.Server object referring to the instance of SQL Server on which AlwaysOn should be enabled.

Examples
  1. This command enables AlwaysOn Availability Groups on the instance of SQL Server located at the specified path:
    C:PS> Enable-SqlAlwaysOn -Path SQLSERVER:SqlComputerInstance
    

    This change requires restarting the instance, and you will be prompted to confirm this restart.

  2. This command enables AlwaysOn Availability Groups on the instance of SQL Server located at the specified path:
    C:PS> Enable-SqlAlwaysOn -Path SQLSERVER:SqlComputerInstance -Force
    

    The -Force option causes the server instance to be restarted without prompting you for confirmation.

  3. This command enables AlwaysOn Availability Groups on the instance of SQL Server named ‘ComputerInstance’:
    C:PS> Enable-SqlAlwaysOn -ServerInstance ComputerInstance
    

    This change requires restarting the instance, and you will be prompted to confirm this restart.

  4. This command enables AlwaysOn Availability Groups on the instance of SQL Server named ‘ComputerInstance’ using Windows authentication:
    C:PS> Enable-SqlAlwaysOn -ServerInstance ComputerInstance -Credential (Get-Credential DOMAINUsername)
    

    You will be prompted to enter the password for the specified account. This change requires restarting the instance, and you will also be prompted to confirm this restart.

  5. This command enables AlwaysOn Availability Groups on the instance of SQL Server located at the specified path, but the command does not restart the instance:
    C:PS> Enable-SqlAlwaysOn -Path SQLSERVER:SqlComputerInstance -NoServiceRestart
    

    The change will not take effect until you manually restart this server instance.

Additional Notes
 
Related Links