I am using this command to pull specific properties from all the vmguests in vCenter.
$vms = Get-View -Server $vcenter -ViewType VirtualMachine -Property Name,Config,Snapshot,Summary,CustomValue,Guest,Runtime.Host,AvailableField,Value,Parent
I want to use the same command against a specific list of vmguests listed in a text file. I don't want to use Get-VM because it's too slow.
So I tried something like this, but it's not working.
$computers = Get-Content "$PSScriptRoot\computers.txt"
$vms = Get-View -Filter @{"Name" = $computers} -Server $vcenter -ViewType VirtualMachine -Property Name,Config,Snapshot,Summary,CustomValue,Guest,Runtime.Host,AvailableField,Value,Parent
How can I run the Get-View command against a specific list of vmguests?
Thanks
The right side value of each line in the Filter parameter, shall be a RegEx expression.
So assuming you have multiple VM names, one per line in the file, you have to separate them with the RegEx OR symbol '|'
Try like this (btw I used splatting to make the long lines more legible)
$sView = @{
Filter = @{"Name" = $computers}
Server = $vcenter
ViewType = 'VirtualMachine'
Property = 'Name','Config','Snapshot','Summary','CustomValue',
'Guest','Runtime.Host','AvailableField','Value','Parent'
}
$vms = Get-View @sView
---------------------------------------------------------------------------------------------------------
Was it helpful? Let us know by completing this short survey here.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
The right side value of each line in the Filter parameter, shall be a RegEx expression.
So assuming you have multiple VM names, one per line in the file, you have to separate them with the RegEx OR symbol '|'
Try like this (btw I used splatting to make the long lines more legible)
$sView = @{
Filter = @{"Name" = $computers}
Server = $vcenter
ViewType = 'VirtualMachine'
Property = 'Name','Config','Snapshot','Summary','CustomValue',
'Guest','Runtime.Host','AvailableField','Value','Parent'
}
$vms = Get-View @sView
---------------------------------------------------------------------------------------------------------
Was it helpful? Let us know by completing this short survey here.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
worked like a charm. good info. Thank you very much!