how to get the drive letter of a USB drive by its name.
I am new to powershell.
I am finding it very difficult to get the name of driver letter and drive name of the USB connected.
What I essentially want to do is I have named my USB drive as "BOOTME" I just want to query by name and get the driver letter.
get-psdrive |format-list using this command I can see my USB drive of description name "BOOTME", don't know how to get the driver letter of this drive. ex: d:\ or e:\
Is there a simpler way we can do this.
I really appreciate your help.
September 17th, 2013 1:56pm
Get-WmiObject -Query "Select * From Win32_LogicalDisk" | ? { $_.driveType -eq 2 } | select volumename,deviceid
September 17th, 2013 2:05pm
Hi,
Give this a shot:
Get-PSDrive |
Where { $_.Description -eq 'BOOTME' } |
Select Root
September 17th, 2013 2:08pm
$letter = get-psdrive | ?{$_.Description -eq 'BOOTME'} | %{$_.name}
September 17th, 2013 4:52pm
$letter = get-psdrive | ?{$_.Description -eq 'BOOTME'} | %{$_.name}
September 17th, 2013 4:55pm
This alternative is better in case there is more than one drive with the BOOTME tag. It returns the first drive letter in that case.
In case there is no drive with a BOOTME tag, it returns an empty string.
$letter = (@(get-psdrive | ?{$_.Description -eq 'BOOTME'}).name + '')[0]
September 18th, 2013 5:52am