Skip to main content
Question

How do I create a worklet to Enable USB Ports?

  • March 20, 2023
  • 0 replies
  • 115 views

dylan
Forum|alt.badge.img

Hi everyone,

I'm currently using the following PowerShell script to disable USB storage devices and enable mouse and keyboard devices:

# Disable USB storage devices
$usbDevices = Get-PnpDevice -Class "USB" -Status OK | Where-Object {$_.Service -eq "USBSTOR"}
foreach ($usbDevice in $usbDevices) {
Disable-PnpDevice -InstanceId $usbDevice.InstanceId -Confirm:$false
}

# Enable mouse and keyboard devices
$mouseDevice = Get-PnpDevice -Class "Mouse" -Status OK | Where-Object {$_.ConfigManagerErrorCode -eq 0}
$keyboardDevice = Get-PnpDevice -Class "Keyboard" -Status OK | Where-Object {$_.ConfigManagerErrorCode -eq 0}
Enable-PnpDevice -InstanceId $mouseDevice.InstanceId -Confirm:$false
Enable-PnpDevice -InstanceId $keyboardDevice.InstanceId -Confirm:$false

# Evaluation code
Write-Output "This code disables USB storage devices and enables mouse and keyboard devices."

However, I need to find an Automox worklet that enables USB drives. Can anyone help me find a worklet that does this?