Lamb-shift polarimeters are used to measure the nuclear polarization of protons and deuterons at energies of a few keV. In combination with an ionizer, the polarization of hydrogen and deuterium atoms was determined after taking into account the loss of polarization during the ionization process. The present work shows that the nuclear polarization of hydrogen or deuterium molecules can be measured as well, by ionizing the molecules and injecting the H2(+) (or D2(+)) ions into the Lamb-shift polarimeter.