In my current playthrough, Codsworth got stuck between being recruited and dismissed. I could be in downtown and he'd stay in Sanctuary, but when I used AFT's "gather all loose items" the items would go to his inventory. Some might consider that a useful way to get junk back to the settlement, I guess. Fortunately the commands quoted below were successful at dismissing him. I'll put them into a batch file for future use.