Glad it's working, and thanks for posting the script, the next NUT user will want it (I hope I'll be able to experiment with NUT in the coming weeks, so I could very well be "the next NUT user").
I tried the PBD part on a lab host running 8.3: xe pbd-list never prints a storage-type line, so that grep finds nothing and step 2 quietly unplugs no PBDs. The 2>/dev/null hides it, and --force isn't an option pbd-unplug knows about. My wild guess is that ejecting the CDs is what fixed it for you.
If you want the unplug to really happen, going through the SR type works on my side, though I only tested it against an ISO SR, not SMB:
H=$(xe host-list hostname=$(hostname) --minimal)
for t in nfs smb iso lvmoiscsi; do
for sr in $(xe sr-list type=$t --minimal | tr , ' '); do
for pbd in $(xe pbd-list sr-uuid=$sr host-uuid=$H currently-attached=true --minimal | tr , ' '); do
xe pbd-unplug uuid=$pbd
done
done
done
Block iSCSI SRs show up as lvmoiscsi, which is why it's not iscsi in the list. @Forza's point about hard mounts may still bite if the share is already gone when the unplug runs; I don't know enough about the SMB side to say.