How to call plugin device from script

What is the correct syntax to call a plugin device from within a script?

For example, I have an all off script that is triggered by a button press. Rather than set up separate actions, I’d like everything to be in a single script.

For the sake of explanation let’s assume the plugin device would be set to “foo.MediaCommand=‘PowerOff’”. What would the line in the script read as?

Ty,

As luck would have it, a recent reply to another post drew attention to some code that shows how to do it.