Hello,
I am connected to multiple vCenters trying to find all the VMs in my environment which have virtual USB controllers. The command is working, but how to I include which vCenter the VM resides in with my results?
$vms = Get-View -ViewType VirtualMachine -Property Name,'Config.Hardware' | Where-Object { $_.Config.Hardware.Device.Where({$_.gettype().name -match 'VirtualUSBController'}) } | Select-Object -ExpandProperty Name
foreach ($vm in $vms){
get-vm -name $vm | select Name,GuestId,@{N="Folder";E={$_.Folder.Name}} | Export-Csv e:\output\usbcontrollervms.csv
}
Try something like this
@dbutch1976 wrote:
Hello,
I am connected to multiple vCenters trying to find all the VMs in my environment which have virtual USB controllers. The command is working, but how to I include which vCenter the VM resides in with my results?
$vms = Get-View -ViewType VirtualMachine -Property Name,'Config.Hardware' | Where-Object { $_.Config.Hardware.Device.Where({$_.gettype().name -match 'VirtualUSBController'}) } | Select-Object -ExpandProperty Name
foreach ($vm in $vms){
get-vm -name $vm | select Name,GuestId,@{N="Folder";E={$_.Folder.Name}} | Export-Csv e:\output\usbcontrollervms.csv
}
Get-View -ViewType VirtualMachine -Property Name,'Config.Hardware','Config.GuestId',Parent |
Where-Object { $_.Config.Hardware.Device.Where( { $_.gettype().name -match 'VirtualUSBController' }) } |
Select-Object Name,
@{N='GuestId';E={$_.Config.GuestId}},
@{N = "Folder"; E = {
(Get-View -Id $_.Parent).Name } },
@{N='vCenter';E={([uri]$_.Client.ServiceUrl).Host}} |
Export-Csv -Path e:\output\usbcontrollervms.csv -NoTypeInformation -UseCulture
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Try something like this
@dbutch1976 wrote:
Hello,
I am connected to multiple vCenters trying to find all the VMs in my environment which have virtual USB controllers. The command is working, but how to I include which vCenter the VM resides in with my results?
$vms = Get-View -ViewType VirtualMachine -Property Name,'Config.Hardware' | Where-Object { $_.Config.Hardware.Device.Where({$_.gettype().name -match 'VirtualUSBController'}) } | Select-Object -ExpandProperty Name
foreach ($vm in $vms){
get-vm -name $vm | select Name,GuestId,@{N="Folder";E={$_.Folder.Name}} | Export-Csv e:\output\usbcontrollervms.csv
}
Get-View -ViewType VirtualMachine -Property Name,'Config.Hardware','Config.GuestId',Parent |
Where-Object { $_.Config.Hardware.Device.Where( { $_.gettype().name -match 'VirtualUSBController' }) } |
Select-Object Name,
@{N='GuestId';E={$_.Config.GuestId}},
@{N = "Folder"; E = {
(Get-View -Id $_.Parent).Name } },
@{N='vCenter';E={([uri]$_.Client.ServiceUrl).Host}} |
Export-Csv -Path e:\output\usbcontrollervms.csv -NoTypeInformation -UseCulture
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hey LucD,
Not sure what's wrong but folder is coming up blank now, was working before.
My bad, typo in that part.
The code above is corrected
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
That's got it, thanks LucD!