The Enterprise-D picks up an odd subspace anomaly & the next thing they know; there's magic in the air as 3 of the Marauders end up on the Flagship of the Federation with no idea how they got there or how they'll get back.
During the final battle, Harry gets thrown into a new universe, landing on the bridge of the USS Enterprise-D. This should take place in about "season 4" of ST:TNG, but I'm not going to be strict about the timeline, using things and events as needed.
Deanna Troi and Data find themselves obliviated and serving as Hogwarts new professors of Divination and Defense Against the Dark Arts. Unaware of their old lives, they try to make do, gradually discovering who they are and their old strengths.