Canadians derailed a train and drove it to City Hall for power after a ice storm https://www.thedrive.com/news/39378/how-canadians-derailed-a-train-and-drove-it-to-city-hall-for-power-after-a-brutal-ice-storm
some place didn't even need to derail the engine, when power lines were next to the tracks.
an entire hospital (St-Hyacinthe iirc) ran on power from a locomotive
@estherschindler that's a brilliant idea. modern freight trains are diesel-electric, probably not too convoluted to have them output that to the power grid.