In 1846 he was promoted second lieutenant and fought in Zachary Taylor's Army of Occupation during the battles of Palo Alto, Resaca de la Palma and Monterrey. He then joined Winfield Scott's army and landed at Vera Cruz and fought in all the battles of Scott's campaign culminating in the fall of Mexico City. He was brevetted captain for gallantry and meritorious conduct in the battles of Contreras and Churubusco and again brevetted to major for his services at the battle of Molino del Rey and received the praise of his division commander, William J. Worth. Prior to the outbreak of the Civil War he was said to have been an intimate friend of Generals Robert E. Lee, Joseph E. Johnston and P. G. T. Beauregard.