How to control power to USB ports using batch

You would need external hardware, such as a USB controlled relay. Windows itself does not provide a API or option to allow the power pins of USB ports to be switched off. This has been answered previously here and summarized history here.


Analysis of the problem

Since Vista, USB devices remain powered-on even after they are safely removed.

The Microsoft article USB Port Remains Active for Disabled or Safely Removed USB Device describes this new behavior :

In Windows XP and Windows Server 2003, when a USB device is marked as Removed, the USB hub port to which it is connected is Disabled. When the port is Disabled, no further USB traffic is sent to the device.

In Windows Vista, Windows Server 2008, Windows 7, and Windows Server 2008 R2, when a USB device is marked as Removed, the USB hub port to which it is connected is not Disabled.

I believe this behavior is what you are trying to change, in order to power-down devices that you have removed.

Solution

Power-down cannot be done via a batch script, but it can be returned to its XP behavior by modifying the registry, either as global setting for all USB devices or per-device.

To apply the workaround globally for all enumerated USB devices,
add a REG_DWORD value named DisableOnSoftRemove that has a value of 1 to the following registry subkey:
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\usbhub\HubG.

To apply the workaround for a specific device,
add a REG_DWORD value named DisableOnSoftRemove that has a value of 1 to the following registry subkey:
HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\usbflags\vvvvpppprrrr
where vvvv is the device's Vendor ID, pppp is the device's Product ID, and rrrr is the device's Revision number (found in Device Manager).