I really don’t want to advise you on the use of this feature because we’re about to release (e.t.a. next week) 7.4, which includes the ability to aggregate a Portfolio based on project (and application) tags. And with the release of this new feature, we deprecate aggregation by custom measure.
So… if you can wait a week to get started, you’ll likely be happier in the long run.
That said, you should be able to programmatically call the same Web APIs (see the link to the onboard api documentation in your footer) that the interface does. Also, I want to point out the difference between a metric (a thing which can be measured) which is set up once by the global admin and made available to all projects, and a measure which is turned on for a project by a project (or global) admin, and then (theoretically) updated periodically.
It’s likely that those first two steps aren’t worth automating, and that the last one might be.