Can anyone explain me why the command
Test-SqlAvailabilityGroup takes too much time ?
Is there a fastest way to check if a an availability group exists or not (preferably on PowerShell) ?
Test-SqlAvailabilityGroup evaluates health of your AG, which may take some time depending upon multiple factors. If you just want to check if AlwaysOn is enabled or not, you can use this
(Get-SqlInstance -ServerInstance 'Myserver').IsHadrEnabled
If above returns 'True', then use below to get list of Availability groups on host
Get-SqlInstance -ServerInstance 'MyServer' | Select AvailabilityGroups