I have multiple availability groups on my SQL Server instance, as its edition is Standard. I want to fail-over all the AG`s from primary node of WSFC, if one AG was failed over. To do that I need to check in my scheduled job if I'm currently on the primary node of WSFC.
I know, that I can check if I'm on primary replica of SQL Server through some system views, related to always on. But I need to handle situation when my primary replica resides on secondary node of WSFC. I have one listener for all AG`s though, so such a situation may occur if AG, tied to listener will fail-over. Is there any ways to get the information I need?