Powershell:如何找到其他-ExpandProperty
我正在尝试将带有 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 IDs,您将看到该设备的 id,我想在 Powershell 中获取此 id,以便我可以使用设备 id 将其分配给我的虚拟机(xp 模式)
我对 powershell 很陌生,也许有一种方法可以查看所有属性 $vpc.USBDeviceCollection 但我不知道如何...
有人可以帮助我吗? 谢谢!
im tring to attach a usb device with an ID to my xp mode (virtual machine).
Here is the code i found on the internet.
# 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)
Now the following line gives the name of the device:
$vpc.USBDeviceCollection | select -ExpandProperty DeviceString
I want to see the ID of the Device. If you go to Device manager and select an "Unknown Device" -properties -details -Hardware IDs you'll see the id of that device and i want to get this id in Powershell so i can assagin it with the device id to my VM(xp mode)
I'm pretty new to powershell, mybe there is a way to see all the properties $vpc.USBDeviceCollection but i dont know how...
Can someone help me out?
Thx!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
VirtualPC.Application 没有 DeviceID 属性。
尝试阅读此处使用 wmi
http://blogs.msdn.com/b/powershell/archive/2007/02/24/displaying-usb-devices-using-wmi.aspx
VirtualPC.Application not have a DeviceID property.
Try read here for got it using wmi
http://blogs.msdn.com/b/powershell/archive/2007/02/24/displaying-usb-devices-using-wmi.aspx