Union Pacific Corp. riled employees recently when it started flying drones over some of its railroad yards to ensure workers were following safety guidelines.

The aerial spotters were looking for any number of behaviors that deviate from the railroad’s rule book, from passing between railcars that are less than 100 feet apart to climbing off moving equipment.

The...