Orchestrates enabling Service Broker across all nodes of an AlwaysOn AG. Operates in two modes: FAILOVER_MODE — when the AG exists and the broker is disabled, the function cycles through each replica (failover → Enable-sqmServiceBroker → failback) to ensure the broker is enabled at the primary level on each node; ENDPOINT_ONLY_MODE — when the broker is already enabled or the database was removed from the AG, creates the SSBEndpoint on each instance without failovers.
Execution Flow
Synopsis
The operating mode is determined after checking both the broker status and AG existence: agExists AND NOT brokerEnabled → FAILOVER_MODE; otherwise → ENDPOINT_ONLY_MODE. In FAILOVER_MODE, each instance is made primary in turn, Enable-sqmServiceBroker is called, and a -WaitBetweenFailovers sleep allows health checks between failovers. After processing all nodes, the original primary is restored via a final failover. The SSBEndpoint uses TCP port 4022 with Windows authentication and grants CONNECT to [PUBLIC].
Requires dbatools and sysadmin permissions on all instances. At least 2 instances must be provided.
FAILOVER_MODE performs multiple failovers — plan for brief availability interruptions. Use in a maintenance window. The -WaitBetweenFailovers default of 15 seconds may need to be increased for slower networks or larger databases.