I'm relatively new to powershell and I am hoping to get some help with an error I'm getting when trying to use Powershell to change the 'failover mode' on the availability replicas in an SQL Always On cluster.
In our test environment, I am able to make the change without error against the six Always On Availability Groups that we have set up. However, in production, I am consistently getting an error when running the Set-SqlAvailabilityReplica command against the three Always On Availability Groups that we have set up in that environment.
The commands I am running:
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.Smo") | Out-Null$SqlServer = New-Object Microsoft.SqlServer.Management.Smo.Server('OurSQLServer')$SqlServer.AvailabilityGroups.AvailabilityReplicas | Set-SqlAvailabilityReplica -FailoverMode 'Automatic'
#$SqlServer.AvailabilityGroups.AvailabilityReplicas | select Name, FailoverMode | Format-Table -AutoSize#$SqlServer.AvailabilityGroups.AvailabilityReplicas | select Name, FailoverMode | Format-Table -AutoSize
The error I am getting:
Set-SqlAvailabilityReplica : The input object cannot be bound to any parameters for the command either because the command does not take pipeline input or the input and its properties do not match any of the parameters that take pipeline input.At line:1 char:60+ $SqlServer.AvailabilityGroups.AvailabilityReplicas | Set-SqlAvailabilityRe ...+ ~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidArgument: ([OurSQLServer]:AvailabilityReplica) [Set-SqlAvailabilityReplica], ParameterBindingException + FullyQualifiedErrorId : InputObjectNotBound,Microsoft.SqlServer.Management.PowerShell.Hadr.SetSqlAvailabilityReplicaCommand
I did compare the powershell versions between test and production using the $psversiontable command and the version info matches. So I'm not sure what else could explain the difference in behavior.
Any help is appreciated. Thank you.