Not very sophisticated but works well to incorporate in applications. There was a situation where I had to grant access to certain ASP pages based onuser's AD group membership: direct or nested. This SP works as good work around.
Overcoming the OPENQUERY Record Limit for AD
Sometimes you have to pull more than 50,000 records. A script to do that inside the 1000 record limit.