Powershell:如何找到另一个-ExpandProperty

时间:2011-10-14 12:22:21

标签: powershell powershell-v2.0 virtual-machine xp-mode

尝试将带有ID的USB设备连接到我的xp模式(虚拟机)。 这是我在互联网上找到的代码。

    # Connect to Virtual PC
$vpc = new-object -comobject "VirtualPC.Application"

# Get VM name
$vmName = Read-host "Specify the name of the virtual machine that you want to use"

# List available USB devices
write-host "The following USB devices are available:"
$vpc.USBDeviceCollection | select -ExpandProperty DeviceString

# Get the USB device name
$usb = Read-host "Enter the name of the USB device that you want to connect to the virtual machine"

# Get the VM object
$vm = $vpc.findVirtualMachine($vmName)

# Get the USB object
$usbDevice = $vpc.USBDeviceCollection | ? {$_.DeviceString -eq $usb} | select -first 1

# Attach the device - this will fail if the VM is not running
$vm.AttachUSBDevice($usbDevice)

现在,以下行给出了设备的名称:

$vpc.USBDeviceCollection | select -ExpandProperty DeviceString

我想查看设备的ID。如果您转到设备管理器并选择“未知设备”-properties -details -Hardware ID,您将看到该设备的ID,我想在Powershell中获取此ID,以便我可以将设备ID与我的VM联系起来(xp模式)

我对powershell很新,mybe有办法看到所有属性$ vpc.USBDeviceCollection但我不知道怎么...

有人可以帮帮我吗? THX!

1 个答案:

答案 0 :(得分:0)

VirtualPC.Application没有DeviceID属性。

请尝试阅读此处以使用wmi

获取它

http://blogs.msdn.com/b/powershell/archive/2007/02/24/displaying-usb-devices-using-wmi.aspx