Heat the oven to 400 F. Butter a 2-quart baking dish.
Cook the spaghetti in boiling salted water for 1 minute less than the package instructions for al dente. Drain.
Melt the butter in a large skillet; add the mushrooms and ham and cook until the mushrooms are browned and the liquids have evaporated. Add the flour to the pan and cook, stirring, for 2 to 3 minutes. Add the chicken broth, sherry (if using), milk, cream, pepper, and nutmeg; cook until thickened. Taste and add salt, as needed.
Add half of the Parmesan cheese and the optional peas if using. Stir the drained spaghetti into the sauce mixture until well blended.
Transfer the spaghetti mixture to a 2 quart baking dish and sprinkle with the remaining Parmesan cheese.
Bake for 25 to 30 minutes.
Keyword ham tetrazzini, one pot meals, pasta casserole