Well, in this fanfiction, the aliens could be after the Philosopher's Stone. They sense its great power from outer space. So they invade Hogwarts. The alien technology might be a match for the magic at first. But then the wizards start to combine different spells in creative ways. For example, Hermione could research ancient spells that could disrupt the aliens' energy fields. And Ron would be there to support Harry as they lead the fight against the invaders.
In a Harry Potter Alien Invasion fanfiction, the aliens might come to Earth because they want to enslave the wizards. They see the magic as a valuable resource. When they invade, they start by attacking Diagon Alley to disrupt the wizarding economy. Harry and his friends are caught off - guard at first. But then they quickly gather allies. They teach some of the non - magical people basic defensive magic so they can also fight. The wizards then use their unique magic, like apparition, to surprise the aliens and fight back.
One possible plot could be that aliens invade Hogwarts. They might be attracted by the powerful magic there. The students and teachers would have to put aside their differences within the wizarding world and unite against the alien threat. Harry Potter and his friends could use their knowledge of magic, like defensive spells, to fend off the aliens.