Powershell and Alwayson Question

  • I'm trying to join an availability group to a cluster node using the command below in powershell. I receive the error also shown below. When I run sp_who2 in management studio I can see that the session of powershell that is running is not in the master database. How do I force this command to be executed within the context of master within powershell?

    set-location sqlserver:\sql\$SecondaryServer\default

    Join-SqlAvailabilityGroup -Path SQLServer:\sql\$SecondaryServer\default -Name $groupname

    Join-SqlAvailabilityGroup : Availability-group DDL operations are permitted only when you are using the master database. Run the USE MASTER command, and retry your availability-group DDL command.

    At line:2 char:26

    + Join-SqlAvailabilityGroup <<<< -Path SQLServer:\sql\$SecondaryServer\default -Name $groupname

    + CategoryInfo : InvalidOperation: (:) [Join-SqlAvailabilityGroup], SqlException

    + FullyQualifiedErrorId : ExecutionFailed,Microsoft.SqlServer.Management.PowerShell.Hadr.JoinSqlAvailabilityGroupCommand

  • If you append -Script to the end of the Join-SqlAvailabilityGroup command it should script it out for you. This could provide additional insight as to where it is trying to do this.

    Also to set a database I believe it would look similar to this:

    SQLSERVER:\SQL\MyComputer\MyInstance\Databases\AdventureWorks2008R2

    - Tony Sweet

  • have you first added the new replica to the AlwaysOn group?

    -----------------------------------------------------------------------------------------------------------

    "Ya can't make an omelette without breaking just a few eggs" 😉

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply