Sathiya
Sathiya

Reputation: 79

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?

Upvotes: 1

Views: 5853

Answers (2)

JPBlanc
JPBlanc

Reputation: 72680

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

Upvotes: 2

ravikanth
ravikanth

Reputation: 25810

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}

Upvotes: 3

Related Questions