Is it possible to run query against only part of the Central Managed Servers? For example, I want to run this query to get the status of some servers having high availability group set up:

SELECT  s.role_desc,  g.name, r.replica_server_name , GETDATE() as checkTime
    FROM sys.dm_hadr_availability_replica_states AS s
    INNER JOIN sys.availability_replicas AS r
        ON s.replica_id = r.replica_id
    INNER JOIN  sys.availability_groups g
        ON r.group_id = g.group_id


...but some of the managed servers are SQL Server 2008, which don't have those views in the query, and hence the query returns error.  

I have tried something like:

SELECT  s.role_desc,  g.name, r.replica_server_name , GETDATE() as checkTime
    FROM sys.dm_hadr_availability_replica_states AS s
    INNER JOIN sys.availability_replicas AS r
        ON s.replica_id = r.replica_id
    INNER JOIN  sys.availability_groups g
        ON r.group_id = g.group_id
where  r.replica_server_name in
(select server_name  FROM msdb.dbo.sysmanagement_shared_registered_servers_internal
where server_name like 'theserversIwant%a'
)


...but it doesn't work. It still queries the entire list of all the managed servers.
Try wrapping your query inside some conditional logic which checks for the @@version.
It will still access all servers in your Central Managed Server list, but it won't throw the error.  Here is an example you could try.

IF (SELECT @@VERSION) LIKE '%2008%'
BEGIN
    SELECT 'not avail on 2008' AS role_desc
        ,'not avail on 2008' AS NAME
        ,'not avail on 2008' AS replica_server_name
        ,GETDATE() AS checkTime
END
ELSE
BEGIN
    SELECT s.role_desc
        ,g.NAME
        ,r.replica_server_name
        ,GETDATE() AS checkTime
    FROM sys.dm_hadr_availability_replica_states AS s
    INNER JOIN sys.availability_replicas AS r
        ON s.replica_id = r.replica_id
    INNER JOIN sys.availability_groups g
        ON r.group_id = g.group_id
END




Regarding your question about saving the results of the CMS query - I'm not aware of a built-in method for doing that.  However, one option (that requires a little extra work) is to:


Run the CMS query, select all of the results grid and choose Copy with Headers.
Head over to DBFiddle and click on the Text To DDL button at the bottom of the page.
Paste the contents of the CMS grid results in the Formatted Text window and enter a table name in the Table Name box.
Click the Preview DDL button which will show you a CREATE TABLE command along with INSERT statements.


You'll have to do some minor modifications to the generated DDL such as removing tick-mark quotes around column names and using brackets around column names that have spaces like [Server Name] or putting brackets around reserved identifiers like [Name].

This will allow you to save the results to a table of your choice for further analysis.