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!
That should be Property instead of ExpandProperty.
Also, note that a VirtualMachine object does not have a Folder property.
You can fetch the name of the VM's Parent, but when that VM is located in the root, it will show the hidden foldername 'vm'
Get-View -ViewType VirtualMachine -Property Name,Parent,'Config.Hardware' |
Where-Object { $_.Config.Hardware.Device.Where({$_.gettype().name -match 'VirtualUSBController'}) } |
Select-Object Name,@{N="Folder";E={(Get-View $_.Parent).Name}}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
That should be Property instead of ExpandProperty.
Also, note that a VirtualMachine object does not have a Folder property.
You can fetch the name of the VM's Parent, but when that VM is located in the root, it will show the hidden foldername 'vm'
Get-View -ViewType VirtualMachine -Property Name,Parent,'Config.Hardware' |
Where-Object { $_.Config.Hardware.Device.Where({$_.gettype().name -match 'VirtualUSBController'}) } |
Select-Object Name,@{N="Folder";E={(Get-View $_.Parent).Name}}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
