The multipole moments of stationary axially symmetric vacuum or electrovacuum spacetimes can be expressed in terms of the power series expansion coefficients of the Ernst potential on the axis. In this paper we present a simpler, more efficient calculation of the multipole moments, applying methods introduced by B\"ackdahl and Herberthson. For the nonvacuum electromagnetic case, our results for the octupole and higher moments differ from the results already published in the literature. The reason for this difference is that we correct an earlier unnoticed mistake in the power series solution of the Ernst equations. We also apply the presented method to directly calculate the multipole moments of a five-parameter charged magnetized generalization of the Kerr and Tomimatsu-Sato exact solutions.