Agree with Beppe, built-in tools are better, faster, and less error-prone.
But perhaps you have some good reasons for it ...
I have "Symantec Endpoint Protection Content Distribution Monitor", I require the query to check out the systems which are in network but not manage by Server.
As I see it, you first need an Unmanaged detector to get the data of the unmanaged or non-SEP devices. Then you may use a query as explained here.
In the same thread, you'll find a query fulfilling your second wish -- but it's avery long one.