Can't create an Availability Group with Powershell when instance uses non-standard port
Change $SqlServerPrimName = "SERVER\INSTANCE,Port" to $SqlServerPrimName = "SERVER\INSTANCE" and change the port for the instance afterwards.


$ComputerName = gc env:computername
$SqlServerPrimName = "SERVER\INSTANCE"
$SQLServerPort = 1433
$wmi = new-object ("Microsoft.SqlServer.Management.Smo.Wmi.ManagedComputer") $computerName
$wmi.ServerInstances["$SqlServerPrimName"].ServerProtocols["Tcp"].IPAddresses["IPAll"].IPAddressProperties["TcpPort"].value = "$portNumber"
$wmi.ServerInstances["$SqlServerPrimName"].ServerProtocols["Tcp"].IPAddresses["IPAll"].IPAddressProperties["TcpDynamicPorts"].value = [System.String]::Empty
#We need to commit the changes by calling the Alter method
$wmi.ServerInstances["$SqlServerPrimName"].ServerProtocols["Tcp"].Alter()