Move the sunroof to a tilted position, if possible. Use a screwdriver or drill to remove the screws that hold the glass panel in place. Gently pop the glass panel out of its frame, and set it aside in a safe spot.
With the sunroof mechanisms exposed, inspect the gears that make it move. Check to see if any gears or components are broken, cracked or stripped. Clean out any debris or grease buildup that has accumulated in the gears or mechanisms.
Have a friend turn on your car and operate the different sunroof positions. Watch as the gears move, looking for problem areas. Look out for gears that stick or a motor that makes noise but does not move the assembly.
Photograph the existing assembly for reference. Carefully remove any gears or motors that are causing problems. Take them to an auto parts store, and buy replacement parts. Replace the old parts, check the performance of the sunroof, and replace the glass panel.