Allow all connected USB devices (Industry 8.1)

7/8/2014

Review a sample PowerShell script that allows all connected USB devices using the USB Filter of your Windows Embedded 8.1 Industry (Industry 8.1) device.

The following sample Windows PowerShell script configures USB Filter to allow connections to all currently attached USB devices. The script creates a function that uses the Windows Management Instrumentation (WMI) providers for USB Filter to obtain a list of all USB ports with connected devices and add permission entries for each connected device.

The function first queries USBF_PortInfo to obtain a list of all USB ports that have the HasDeviceAttached property set to true.

Next, the function adds permission entries to USBF_PermissionEntry for each connected USB device, if no permission entry already exists for that device.

AllowAllConnectedUSBDevices

function AllowAllConnectedUSBDevices()
{
    # Define the namespace for USB_Filter

    $ns = "root/standardcimv2/embedded"

    # Get information from USBF_PortInfo for all connected USB devices

    $usbConnected = get-wmiobject -namespace $ns -class USBF_PortInfo | ? {$_.HasDeviceAttached -eq $true}

    # Add permission entries for every connected USB device.

    foreach ($usbPort in $usbConnected)
    {
        # Check to see if a permission entry already exists.

        $permissionEntry = @{}
        $permissionEntry = get-wmiobject -namespace $ns -class USBF_PermissionEntry | 
            ? {$_.PortLocationPath -eq $usbPort.PortLocationPath -and 
            $_.DeviceClassID -eq $usbPort.DeviceClassID -and 
            $_.DeviceVendorID -eq $usbPort.DeviceVendorID -and 
            $_.DeviceProductID -eq $usbPort.DeviceProductID}

        # If no permission entry exists already, add an entry to permit the specific attached USB device.

        if ($permissionEntry.Count -eq 0)
        {
            set-wmiinstance -namespace $ns -class USBF_PermissionEntry -argument @{
                PermissionLevel = 2;
                PortLocationPath = $usbPort.PortLocationPath;
                DeviceClassID = $usbPort.DeviceClassID;
                DeviceVendorID = $usbPort.DeviceVendorID;
                DeviceProductID = $usbPort.DeviceProductID
                } | Out-Null;

            # Display added permission entry information

            echo "Added the following permission entry:”
            echo "  Port: $usbPort.PortLocationPath"
            echo "  Device class ID: $usbPort.DeviceClassID"
            echo "  Device vendor ID: $usbPort.DeviceVendorID"
            echo "  Device product ID: $usbPort.DeviceProductID"
            echo " "
        }
    }
}

After you create the function, you can call the function by typing the following command at a Windows PowerShell command prompt:

AllowAllConnectedUSBDevices

See Also

Reference

USB Filter WMI provider reference

Concepts

USB Filter