Get NETDOM from Microsoft and then script what you want with it.

There are some UDFs here but not sure they're as complete as you need for what you're wanting to do but they might be. Search in the UDF forum.