This is Corollary 3.8 in Cohen, H.; Lenstra, H. W., Jr. Heuristics on class groups. Number theory (New York, 1982), 26–36, Lecture Notes in Math., 1052, Springer, Berlin, 1984 (MR0750661, ZbMath).
In this paper you will find many formulas for averages of various functions over abelian groups weighted by inverse size of the automorphism group.