Hello,
I need to do a search and destroy of all VMs which use a VirtualUSBController. For starters I found this great one-liner:
Get-View -ViewType VirtualMachine -Property Name,'Config.Hardware' | Where-Object { $_.Config.Hardware.Device.Where({$_.gettype().name -match 'VirtualUSBController'}) } | Select-Object -ExpandProperty Name
My issue is that I need to see the folders that these VMs are in so that I can find out who owns them, with that in mind I'd like to see additional properties such as the folder name, comments, etc. I tried this:
Get-View -ViewType VirtualMachine -Property Name,'Config.Hardware' | Where-Object { $_.Config.Hardware.Device.Where({$_.gettype().name -match 'VirtualUSBController'}) } | Select-Object -ExpandProperty Name,@{N="Folder";E={$_.Folder.Name}}
Select-Object : Cannot convert 'System.Object[]' to the type 'System.String' required by parameter 'ExpandProperty'. Specified method is not supported.
What is the correct way to get this information? I'm not familiar with the Select-Object -ExpandProperty command.
Thanks!