October 15, 2019 at 6:23 pm
Hi,
for SQL Server 2017, I am trying to create a new AG. Via SSMS and the wizard it works fine, however, the PowerShell cmdlet for New-SqlAvailabilityGroup throws an error:
import-module sqlserver
$primary=(Get-Item -Path ("SQLSERVER:\SQL\Server1\Default"))
$SMOServer=get-Item -Path "SQLSERVER:\SQL\Server2\Default"
[Microsoft.SqlServer.Management.Smo.AvailabilityReplica]$SecondaryReplica=New-SqlAvailabilityReplica `
-Name ("Server2\Default") `
-EndpointUrl ("TCP://Server2.Domain:5022") `
-FailoverMode "Manual" `
-AvailabilityMode "AsynchronousCommit" `
-AsTemplate -SeedingMode Automatic `
-Version ($SMOServer.Version) -ConnectionModeInSecondaryRole AllowReadIntentConnectionsOnly `
-BackupPriority 80 `
-ReadonlyRoutingConnectionUrl ("TCP://Server2.Domain:1433")
[Microsoft.SqlServer.Management.Smo.AvailabilityReplica]$primaryReplica=New-SqlAvailabilityReplica `
-Name ("Server1\Default") `
-EndpointUrl ("TCP://Server1.domain:5022") `
-FailoverMode "Manual" `
-AvailabilityMode "SynchronousCommit" `
-AsTemplate `
-Version ($SMOServer.Version) -ConnectionModeInPrimaryRole AllowAllConnections `
-BackupPriority 90 -SeedingMode Automatic
New-SqlAvailabilityGroup -Name ("AG") -AvailabilityReplica ($primaryReplica,$SecondaryReplica) -InputObject $Primary
Error:
New-SqlAvailabilityGroup : The current instance 'Server1' must be included as an availability replica to create the availability group 'AG'.
Does anyone has an idea? Currently not using DSC.
Thanks
Chris
October 16, 2019 at 8:53 am
Hi,
I think I found the issue. In some documentation I found that when creating the replica the Name should be ServerName\InstanceName which is not correct. When redoing everything in .net with SMO I the constructor of the Replica contains the AG and the Name of the Server.
KR
Viewing 2 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply