获取USB驱动器号 [英] Get USB drive letter
问题描述
我尝试运行非常简单的wmic命令来输出连接的USB驱动器的驱动器号。该命令是" wmic logicaldisk,其中drivetype = 2获取deviceid / format:value "。问题是输出是" DeviceID = X :",
我希望输出只显示 X:而不是"DeviceID ="。此外,我正在使用MSP软件,它允许从WMI查询创建变量,我无法弄清楚上述场景的语法。所以基于他们的在线帮助(下面),
我的语法是root \cimv2:Win32_LogicalDisk ....但是那么呢?使用root\cimv2:Win32_LogicalDisk.DriveType [2] .DeviceID不起作用。
Im trying run to very simple wmic command to output the drive letter of the connected USB drive. The command is "wmic logicaldisk where drivetype=2 get deviceid /format:value". The problem is that the output is "DeviceID=X:",
i want the output to show just X: without "DeviceID=". Also, i'm using an MSP software which allows creating variables from WMI queries, i cant figure out the syntax for the above scenario. So based on their online help (below),
my syntax is root\cimv2:Win32_LogicalDisk.... but then what? Using root\cimv2:Win32_LogicalDisk.DriveType[2].DeviceID does not work.
WMI属性 - WMI命名空间,类和属性。指定WMI属性的格式为
NameSpace:Class.Property
。例如, root \ cimv2:Win32_OperatingSystem.FreePhysicalMemory
。使用以下语法指定实例:
NameSpace:Class [N] .Property
其中 [N]
是实例编号。例如,
root \cimv2:Win32_OnboardDevice [3] .Description
。第一个实例可以指定或不指定
[1]
实例编号。
WMI Property - A WMI namespace, class, and property. The format of the specified WMI property is
NameSpace:Class.Property
. For example, root\cimv2:Win32_OperatingSystem.FreePhysicalMemory
. Specify an instance using the following syntax:
NameSpace:Class[N].Property
where [N]
is the instance number. For example,
root\cimv2:Win32_OnboardDevice[3].Description
. The first instance may be specified with or without specifying the
[1]
instance number.
推荐答案
只需删除"/ format:value"即可部分命令。 你需要跳过输出的第一行(标题行),否则它应该可以工作。
Just get rid of the "/format:value" part of the command. You'll need to skip the first line of the output (a header row), but otherwise, it should work.
wmic logicaldisk where drivetype=2 get deviceid
这篇关于获取USB驱动器号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!