I dont know how to do this via script but we use Capacity IQ to do it. You can dowload a 60 day free trial of CapIQ and install the appliance, give it some time to gather info and then run the reports to gather all those metrics. It will give you oversized VMs and undersized VMs so you can better tweek and balance your systems. It does a lot of other stuff too. Worth atleast getting the trial. The longer you run it the better the porojections on future capacity are, but for what you are looking for if it runs for a day you will see your oversized and undersized VMs.
Mike P