Powershell
--
Questions
--
Followers
Top Experts
Zero AI Policy
We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.
LogicalDisk
DeviceID Â Â : M:
DriveType   : 3
ProviderName :
FreeSpace   : 1130642976768
Size     : 4000776187904
VolumeName  : FreeAgent GoFlex Drive
Maps to the following USBControllerDevice - Device ID
Disk drive  disk   USBSTOR\DISK&VEN_SEAGATE&P
gwmi win32_diskdrive | ?{$_.interfacetype -eq "USB"}
win32_logicalDisk information
win32_diskdrive information
win32_usbcontrollerdevice information
As they each pertain to the specific, volumename or drive letter provided.
Does that provide the neccessary clarification?






EARN REWARDS FOR ASKING, ANSWERING, AND MORE.
Earn free swag for participating on the platform.
Return formatting is very, very rough at the moment, if you need help cleaning it up please yell; you'll need to tell me exactly what you want to see.
Chris
Function Get-USBStorage {
[CmdLetBinding(DefaultParameterSetName = "DriveLetter")]
Param(
[Parameter(Position = 1, Mandatory = $True, ParameterSetName = "DriveLetter")]
[String]$DriveLetter,
[Parameter(Mandatory = $True, ParameterSetName = "VolumeName")]
[String]$VolumeName
)
If ($PsCmdLet.ParameterSetName -eq "DriveLetter") {
$Filter = "DeviceID LIKE '$DriveLetter%'"
} Else {
$Filter = "VolumeName LIKE '$VolumeName%'"
}
Get-WmiObject Win32_LogicalDisk -Filter $Filter | ForEach-Object {
$Partition = Get-WmiObject -Query "ASSOCIATORS OF {Win32_LogicalDisk.DeviceID='$($_.DeviceID)'} WHERE AssocClass = Win32_LogicalDiskToPartition" |
Select-Object * -Exclude __*
$PhysicalDisk = Get-WmiObject Win32_DiskDrive -Filter "Index=$($Partition.DiskIndex)" | Select-Object * -Exclude __*
$PNPDevice = Get-WmiObject Win32_PNPEntity -Filter ("PNPDeviceID='$($PhysicalDisk.PNPDeviceID)'" -Replace '\\', '\\')
$USBController = Get-WmiObject -Query "ASSOCIATORS OF {$($PNPDevice.__RELPATH)} WHERE AssocClass = Win32_USBControllerDevice" | Select-Object * -Exclude __*
# Rough return
# LogicalDisk
$_ | Select-Object *
# Physical Disk
$PhysicalDisk
# USB Controller
$USBController
}
}
Get-USBStorage "G:"
This is exactly what I was looking for can you walk me through this a bit? I understand the getting and setting the parameters but the associators  has me a bit confused and how I would get a single piece of information to use it in a susequent test specifically the PNPDeviceID         : USBSTOR\DISK&VEN_GENERIC&P
and making sure that is a known value attached to the USB device with the letter G: or VolumeName Xvol.
Thanks,
Get-WmiObject -Query "ASSOCIATORS OF {Win32_LogicalDisk.DeviceI
You should find it returns a number of different classes, normally we get:
Win32_Group - Holds the owner of the logical disk
Win32_Directory - Data about "C:" as a directory (folder)
Win32_QuotaSetting - A bit OS dependent, and probably all unset (0 / -1)
Win32_DiskPartition - The one we actually want
Win32_ComputerSystem - The computer which owns everything above
We tell the query to use Win32_LogicalDiskToPartiti
Get-WmiObject -Query "ASSOCIATORS OF {Win32_LogicalDisk.DeviceI
Both return the same, but the original is more efficient.
Chris

Get a FREE t-shirt when you ask your first question.
We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.
Powershell
--
Questions
--
Followers
Top Experts
Windows PowerShell is a task automation and configuration management framework from Microsoft, consisting of a command-line shell and associated scripting language built on the .NET Framework. PowerShell provides full access to the Component Object Model (COM) and Windows Management Instrumentation (WMI), enabling administrators to perform administrative tasks on both local and remote Windows systems as well as WS-Management and Common Information Model (CIM) enabling management of remote Linux systems and network devices.