Preheat oven to 375°.
Heat oil in a small nonstick skillet over medium-high heat. Add shallots and garlic; sauté 2 minutes or until tender. Remove from heat; stir in ham, 1/4 teaspoon salt, 1/4 teaspoon pepper, nutmeg, and spinach. Combine milk, flour, 1/2 teaspoon pepper, and 1/4 teaspoon salt, stirring with a whisk.
Arrange half of potato slices in an 8-inch square baking pan coated with cooking spray; sprinkle with 1/4 teaspoon salt. Spread spinach mixture over potato slices. Arrange remaining potato slices over spinach mixture; pour milk mixture over top. Sprinkle with 1/4 teaspoon salt. Cover with foil coated with cooking spray. Bake at 375° for 1 hour and 15 minutes or until potato is tender. Uncover and sprinkle with cheese; bake an additional 15 minutes.
Broil gratin for 2 minutes or until cheese is lightly browned.