Powershell:如何找到其他-ExpandProperty

发布于 2024-12-10 04:47:39 字数 1154 浏览 1 评论 0原文

我正在尝试将带有 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

再可℃爱ぅ一点好了 2024-12-17 04:47:39

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文