Control MacBook Pro (2019) Thunderbolt / USB-C port power individually (on/off, e.g., via console command) [duplicate]

I spent a lot of time researching this problem some years ago - my conclusion is that it is simply not possible with the information available to us. The control of the power happens at a much lower level than the macOS kernel itself, so it is not just a question of configuring macOS or poking at the right kernel data structure. You have to modify firmware which is not possible for ordinary users.

The only working solution I found is to use a hub. This worked very well for me. If you have a hub that supports ganged power switching, you can easily turn off/on the power for each gang (set of ports). Similarly if you have a hub that supports per-port power switching, you can turn off/on each port on the hub individually.

You can download software for macOS to control the hub from here:

https://github.com/mvp/uhubctl

Note that this utility only supports controlling hubs that allow per-port power switching. The web site has a list of supported USB hubs.

Once I went with the hub solution, the hardest part really was finding a USB hub that supports ganged or per-port power switching. The actual software part is very easy.