I just want to add a simple way to find the courses, external tool IDs and using those results in the script to remove the tools.
I have a report for our institution that lists all external tools placed at the course level, with the canvas course ID, the course state, the term, the tool name, the tool ID, and the launch URL, so that a given tool can be easily found.
If you're using canvas data, (and I believe it can be up to 48 hours old, but I'm sure someone will correct me of I'm wrong), you can query on the course_dim, enrollment_term_dim, and external_tool_activation_dim tables, to retrieve only the tools added at the course level.