You could take a look at following articles:
https://gallery.technet.microsoft.com/scriptcenter/Group-Policy-cleanup-c8b2bbea
https://community.spiceworks.com/scripts/show/1875-ad-cleanup
Alternatively, you may also try the below automated solutions to clean Active Directory and Group Policy
https://www.lepide.com/lepideauditor/active-directory-cleanup.html
https://sdmsoftware.com/group-policy-blog/group-policy-cleanup/new-options-group-policy-cleanup-gpo-exporter/