 When the 7th New York Militia disbanded later that spring, Shaw secured an officer's commission in the 2nd Massachusetts Infantry. He saw action at the battles of Front Royal and Cedar Mountain in Virginia in 1862, opposing Thomas Stonewall Jackson's Shenandoah Valley Campaign.