After the war, Stanley was appointed colonel of the 22nd U.S. Infantry, primarily serving in the Dakota Territory until 1874. He commanded the Yellowstone Expedition of 1873, successfully conducting his troops through several unmapped areas, and his favorable reports on the country led to subsequent settlement of the region. In 1879, Stanley and his regiment were reassigned to Texas to suppress Indian raids in the western portion of the state. He was ordered to Santa Fe, New Mexico, in 1882, and placed in command of the District of New Mexico. In March 1884, he was appointed a brigadier general in the regular army, and assigned command of the Department of Texas. He retired in 1892.