I am trying to create an Always On Availability Group with PowerShell, something I have done many times before but am hitting an issue now that I am using non-standard ports for the SQL Instance
I generally use a slightly modified version of this script
But I get an error saying that the current instance SERVER\INSTANCE,Port must be added to the availability group before it can be created. Now obviously that is the value I pass in at the top of the script
$SqlServerPrimName = "SERVER\INSTANCE,Port"
Which is then used to create a SMO object
$SqlServerPrim = New-Object Microsoft.SqlServer.Management.Smo.Server($SqlServerPrimName)
And then added to the Availability Group here
But it obviously is not working!
I notice also that if you try and call $SQLServerPrim it comes back empty for InstanceName even though the object is correctly loaded with other values
Creating an Availability Group through the GUI works
Using the New-SQLAvailability* Cmdlets have the same error
Any idea what I need to change in the code to make this work?