AppleScript will allow you to determine, or exclude, locally (USB) mounted, or NAS mounted drives, and then eject them.
-- in this example, "T M" is the name of the Time Machine drive which is not to be ejected
set excluded to {"home", "net", "T M"}
tell application "Finder"
set alist to (every disk whose ejectable is true or local volume is false and excluded does not contain its name)
log alist
(*
repeat with adrive in alist
eject adrive
end repeat
*)
end tell
I have excluded my Time Machine drive in the above example. Otherwise, a mounted USB SSD, and a Synology NAS network share mounted to my Desktop are detected, and ejected. There is an AppleScript block comment around the ejection repeat block in the above code, because the first time the code is run, you should determine what the list alist contains for your usage.
Launch the Script Editor from Dock : Launchpad : Other : Script Editor. On the bottom of the Script Editor, you will see three icons:
Click the right-most icon, and this will open a display area whose heading will be Result, Messages, Events, and Replies. By clicking Replies, you can see the results of the AppleScript running and log command output.
Copy and paste the above AppleScript into the Script Editor, Click the hammer (compile) button, and then the run button. It is likely that when you uncomment the repeat block that you will see error number 0 following each eject. This is normal.