I've been experimenting with this (it's in Babashka, which is for scripting Clojure, but you can do it with just bash, if your bash-fu is stronger than mine :D ):
It basically just moves all workspaces with positive IDs (so not the special workspace) to the external monitor, which seems to have a consistent ID of 1.