This mantra appears in the Ganapati Atharvashirsha Atharva veda.
It is considered to be the most important texts on Lord Ganesha.
Atharva means firmness, oneness of purpose, while shIrSha means intellect (directed towards liberation).
The mantra is also found in the Narada Purana, among other texts, and this below is taken from the Narada Purana.
"The immutable, the consort of Vishnu, the wife of Shambhu, minaketana, smriti, mamsa adorned with indu with manu and with the moon in the crest, Ganapati in the dative, then at the end vara veranda be added, then at the end of sarva one should utter janam, then add me vasham anaya bring them all to my control.
The mantra ends in vahnipriya "svaha" with twenty-eight letters.
Its sage is Ganaka, the metre nivrit Gayatri etc., the presiding deity is Ganesha.
The Bija is six shaktis beginning with "a" and the application of it is for the proportion of Mahaganapati".