any idea how I can filter for VMs with powered on state and guest OS of windows using get-view?
get-view -viewtype virtualmachine -property Name,summary.runtime -filter @{ $_.summary.runtime.powerstate -eq "PoweredOn"} is not working
You mean the -Property parameter on the Get-View cmdlet?
Normally the Get-View cmdlets returns the object(s) with values for all properties of each object.
If you only need a specific property, you can specify it on this parameter.
The fewer properties the faster the Get-View cmdlet will be, especially in bigger environments.
For example the following will return all VirtualMachine objects, but only the Name property will have a value.
Get-View -ViewType VirtualMachine -Property Name
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Try something like this
Get-View -ViewType VirtualMachine -Filter @{'Runtime.PowerState'='poweredOn';'Guest.ToolsState'='ToolsOk'} |
Select Name,
@{N="Tools Status"; E={$_.Guest.Toolsstatus}},
@{N="Guest OS";E={$_.Guest.Guestfullname}},
@{N="PortGroup";E={$_.Guest.Net.Network -join '|'}},
@{N="vcenter";E={([uri]$_.Client.ServiceUrl).Host}}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
If you don't have the VMware Tools installed, you can do
Get-View -ViewType VirtualMachine -Filter @{
'Runtime.PowerState'='poweredOn'
'Config.GuestFullName'='Window'
} |
Select Name
For a more accurate filter with VMware Tools, you can be more specific on the Windows OS you want to filter.
Like for example
Get-View -ViewType VirtualMachine -Filter @{
'Runtime.PowerState'='poweredOn'
'Guest.GuestFullName'='Windows Server 2016'
} |
Select Name
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
thanks Luc. when and what is the -property for ?
You mean the -Property parameter on the Get-View cmdlet?
Normally the Get-View cmdlets returns the object(s) with values for all properties of each object.
If you only need a specific property, you can specify it on this parameter.
The fewer properties the faster the Get-View cmdlet will be, especially in bigger environments.
For example the following will return all VirtualMachine objects, but only the Name property will have a value.
Get-View -ViewType VirtualMachine -Property Name
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thanks
Hi
is there a faster way to run this query?
Try like this
$filterHash = @{
'Runtime.PowerState'="^(?!poweredOff)"
'Guest.GuestFamily'="^(?!windowsGuest)"
'Guest.ToolsStatus'="toolsOld"
}
$properties = 'Name','Runtime.PowerState',
'Guest.GuestFamily','Guest.ToolsStatus','Guest.GuestFullName'
Get-View -ViewType VirtualMachine -Property $properties -Filter $filterHash |
Select Name,
@{N='OS';E={$_.Guest.GuestFullName}},
@{N='ToolsStatus';E={$_.Guest.ToolsStatus}} |
Export-Csv vmtools-linux.csv -NoTypeInformation -UseCulture
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thanks Luc.
another question on filter
how do I filter on name vmhosts that match
get-view -viewtype hostsystem -filter @{'Name'="vmhost006*"} -property NAme | select Name
I want to filter on hosts that only match vmhost006*
Use the RegEx anchor '^'
Get-View -viewtype HostSystem -Filter @{'Name'="^vmhost006"} -Property NAme | select Name
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Trying to get vms with portgroup info but not working
'Guest.Net.NEtwork'="*"
but not working
any idea?
actually trying to do this with get-view
get-vm | ? {$_.powerstate -eq "PoweredON" -and $_.extensiondata.guest.toolsstatus -ne "Toolsok"} | select Name, @{n="Tools Status"; E={$_.extensiondata.guest.Toolsstatus}}, @{n="Guest OS";e={$_.extensiondata.guest.guestfullname}}, @{n="PortGroup";e={$_.extensiondata.guest.net.network}}
, @{n="vcenter";e={$_.Uid.Split(":")[0].Split("@")[1]}} | out-gridview
any idea?
Try something like this
Get-View -ViewType VirtualMachine -Filter @{'Runtime.PowerState'='poweredOn';'Guest.ToolsState'='ToolsOk'} |
Select Name,
@{N="Tools Status"; E={$_.Guest.Toolsstatus}},
@{N="Guest OS";E={$_.Guest.Guestfullname}},
@{N="PortGroup";E={$_.Guest.Net.Network -join '|'}},
@{N="vcenter";E={([uri]$_.Client.ServiceUrl).Host}}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
The performance varies for me, in many occasiont the get-vm and filter aftwards is faster...
Will i see big benefits if the latency to the VCenter is really bad?
Is the big benefit that i use less API calls with the Get-View option?
The Get-VM cmdlet has been optimised, so the execution time difference between Get-VM and Get-View has been minimised.
The Get-View cmdlet still has an advantage when you only need to extract a limited set of properties.
When the VCSA latency is high I suspect both cmdlets will suffer.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference