Yep! More than once for that matter:
The Old Swiss Confederacy had acquired a reputation of invincibility during these earlier wars, but expansion of the federation suffered a setback in 1515 with the Swiss defeat in the Battle of Marignano. This ended the so-called "heroic" epoch of Swiss history
But the Swiss didn't just fight furreners:
The success of Zwingli's Reformation in some cantons led to inter-cantonal religious conflicts in 1529 and 1531 (Wars of Kappel). It was not until more than one hundred years after these internal wars that, in 1648, under the Peace of Westphalia, European countries recognized Switzerland's independence from the Holy Roman Empire and its neutrality.Still, that didn't stop 'em fighting each other:
During the Early Modern period of Swiss history, the growing authoritarianism of the patriciate families combined with a financial crisis in the wake of the Thirty Years' War led to the Swiss peasant war of 1653. In the background to this struggle, the conflict between Catholic and Protestant cantons persisted, erupting in further violence at the Battles of Villmergen in 1656 and 1712.But, the ultimate humiliation occurred during the Napoleonic era.
In 1798, the revolutionary French government conquered Switzerland and imposed a new unified constitution. This centralised the government of the country and effectively abolished the cantons and Mülhausen and Valtellina valley separated from Switzerland. The new regime, known as the Helvetic Republic, was highly unpopular. It had been imposed by a foreign invading army and destroyed centuries of tradition, making Switzerland nothing more than a French satellite state. The fierce French suppression of the Nidwalden Revolt in September 1798 was an example of the oppressive presence of the French Army and the local population's resistance to the occupation.Guess having all those guns didn't help keep the peace!
When war broke out between France and its rivals, Russian and Austrian forces invaded Switzerland. The Swiss refused to fight alongside the French in the name of the Helvetic Republic. In 1803 Napoleon organised a meeting of the leading Swiss politicians from both sides in Paris. The result was the Act of Mediation which largely restored Swiss autonomy and introduced a Confederation of 19 cantons. Henceforth much of Swiss politics would concern balancing the cantons' tradition of self-rule with the need for a central government.
In 1815 the Congress of Vienna fully re-established Swiss independence and the European powers agreed to permanently recognise Swiss neutrality. Swiss troops still served foreign governments until 1860 when they fought in the Siege of Gaeta. The treaty also allowed Switzerland to increase its territory, with the admission of the cantons of Valais, Neuchâtel and Geneva. Switzerland's borders have not changed since.