简体   繁体   中英

Getting location information of the connected USB device

what is the powershell command to read the following registry entry?

 HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum\USB\VID_03A8&PID_0258\6&af75239&0&3\LocationInformation

I tried the following code, i used to get the Device information only

gwmi Win32_USBControllerDevice |%{[wmi]($_.Dependent)} |
Sort Manufacturer,Description,DeviceID |
Ft -GroupBy Manufacturer DeviceID

how to get the location information of the connected usb device?

Look at Get-ItemProperty Cmdlet with registry Provider Path.

For example,

Get-ItemProperty -path HKLM:\SOFTWARE\Microsoft\PowerShell\1\ShellIds\Microsoft.PowerShell

Try this for getting location information for all USB devices:

$devid = gwmi Win32_USBControllerDevice |%{[wmi]($_.Dependent)} | Select -ExpandProperty DeviceID
$devid | % { Get-ItemProperty "HKLM:\SYSTEM\CurrentControlSet\Enum\$_" -Name LocationInformation -ErrorAction SilentlyContinue}

Are you looking for that :

Get-ItemProperty -Path 'HKLM:\SYSTEM\CurrentControlSet\Enum\USB\VID_03F0&PID_1F1D\5&3aded796&0&2' -Name LocationInformation


PSPath              : Microsoft.PowerShell.Core\Registry::HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum\USB\VID_03F0&PID_1F1D\5&3aded796&0&2
PSParentPath        : Microsoft.PowerShell.Core\Registry::HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum\USB\VID_03F0&PID_1F1D
PSChildName         : 5&3aded796&0&2
PSDrive             : HKLM
PSProvider          : Microsoft.PowerShell.Core\Registry
LocationInformation : Port_#0002.Hub_#0004

Or

(Get-ItemProperty -Path 'HKLM:\SYSTEM\CurrentControlSet\Enum\USB\VID_03F0&PID_1F1D\5&3aded796&0&2' -Name LocationInformation).LocationInformation
Port_#0002.Hub_#0004

You can get the connected devices using :

Get-WmiObject Win32_USBHub

You just need to join the two results for exemple for my hard drive :

$PnpdeviceId = (gwmi win32_USBHub | where { $_.name -like '*stockage*'}).PNPDeviceID
(Get-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Enum\$PnpdeviceId" -Name LocationInformation).LocationInformation

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM