Dynamical potentials appear in many advanced electronic-structure methods, including self-energies from many-body perturbation theory, dynamical mean-field theory, electronic-transport formulations, and many embedding approaches. Here, we propose a novel treatment for the frequency dependence, introducing an algorithmic inversion method that can be applied to dynamical potentials expanded as sum over poles.