+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
I may have found a clue, but no idea why the values are different for you.
Code:
$USB_DeviceIDs = @(Get-PnpDevice -PresentOnly | where { $_.Service -eq 'USBSTOR' } | foreach { ($_.PNPDeviceID -split '\\')[2] })
(Get-CimInstance -ClassName Win32_DiskDrive | where { (($_.PNPDeviceID -split '\\')[-1] -split '&')[0] -in $USB_DeviceIDs } | Get-CimAssociatedInstance -ResultClass Win32_DiskPartition | Get-CimAssociatedInstance -ResultClass Win32_LogicalDisk | where { $null -ne $_.Name }).Name.SubString(0,1)
My Computer
At a glance
Windows 7
- OS
- Windows 7










