WARNING: This page is about a different car, the 2005 BMW 745i, 2004 BMW 745i, 2003 BMW 745i, and 2002 BMW 745i. However, it is still accessible from the selected car via links, so may be relevant.
Adjust height of sunroof lid (1) to roof (2) with special tool 00 9 315 (gap wedge).
Fig 1: Adjusting Height Of Sunroof Lid
Courtesy of BMW OF NORTH AMERICA, INC.
Press sunroof lid at front and rear up or down until ideal position is reached.