This article contains a PM Aged Trial Balance script that is a work in progress. I don't have signoff yet, so there are probably some issues with it. But it's a good start.
Do not use this in production until you've proved the data.