How can i search a host using its MoRef, below code does not work:
Get-View -viewtype HostSystem -Filter @ {"HostId"="Host-139"}
Luc,
I was referring to the construction of the ManagedObjectReferen object.
I wonder why you can't use the MoRef property. Maybe it's a bug.
I can use other moref properties, but NOT the MoRef property
The following example works:
$v = get-view -ViewType virtualmachine -filter @{"runtime.host"="^host-2116$"}
This wil return all vms from host-2116. The runtime.host porperty is of type ManagedObjectReference.
The 'key' part has to be a property of the HostSystem object, so you would have to look for a property under Extensiondata.
And HostId doesn't exist there.
You can use nested properties for the Key part. So "MoRef.Value" is not accepted either.
Afaik the -Filter parameter only accepts hashtable{string,string} arguments so you can't pass a MoRef in the Value property either.
But why can't you do this with the info you have
$t = New-Object VMware.Vim.ManagedObjectReference
$t.Type = "HostSystem"
$t.Value = "host-139"
Get-View -Id $t
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
I need to search for 5-7 hosts with MoRef as only identifier to search for.
So I search for viewType as hostSystem and want to filter output for few hosts only and with selective properties only. What can be done here ?
How to enumerate "extensionData" or property names that we can search for ?
tried Moref.Value, HostId.Value --doesn't work
Do the filtering outside of the Get-View cmdlet
Something like this for example
$targets = "host-123","host-456","host-789"
$servers = Get-View -ViewType HostSystem | where {$targets -contains $_.Extensiondata.MoRef.Value}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Remember that the Value property of the MoRef is Case Sensitive!
It looks as if the Key part of the -Flter parameter only accepts level 1 properties.
And it doesn't seem to convert complex properties to [string] format either
Get-View -ViewType HostSystem -Filter @{"MoRef"="HostSystem-host-123"}
doesn't work either. It throws an InvalidProperty error.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Yes, but the -contains operator isn't case-sensitive
Not sure I get what you are trying to say ?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
i want to retrieve only selective hosts, so if i do the filter outside of get-view, it will take lot of time to first query vcenter and then i filter at client side.
i wish to filter the object at server level, so i get what i want, just what i want
can tou give us an example for moref as filter
Then you will have to code your own PropertyCollector and use a PropertyFilter I'm afraid.
The -Filter implementation on the Get-View doesn't seem to allow what you are aiming to do.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Luc,
I was referring to the construction of the ManagedObjectReferen object.
I wonder why you can't use the MoRef property. Maybe it's a bug.
I can use other moref properties, but NOT the MoRef property
The following example works:
$v = get-view -ViewType virtualmachine -filter @{"runtime.host"="^host-2116$"}
This wil return all vms from host-2116. The runtime.host porperty is of type ManagedObjectReference.
Thanks for the example. MoRef filter appears to be buggy.
I found out an equivalent property for hostSystem and observed the propertyname or value is case in-insensitive, it works.
get-view -viewtype hostsystem -filter @{"CoNfig.hoST"="hOsT-107"}
thanks a lot, much appreciated.
By the way, how do you get "ExtensionData", it's not there for a host view, atleast for me 🙂
Thanks for being such a great help
No, it exists on the .Net object not on the HostSystem object.
I wanted to say that you should look at the properties under there
Get-VMHost MyHost | Select -ExpandProperty Extensiondata
The Extensiondata property maps to the HostSystem object.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
😞 not working for me PS M:\Documents\MyData\csv_scripts> get-vmhost 50001.domain.net | fl * State : Connected ConnectionState : Connected PowerState : PoweredOn VMSwapfileDatastoreId : VMSwapfilePolicy : Inherit ParentId : ClusterComputeResource-domain-c3204 Manufacturer : HP Model : ProLiant BL685c G1 NumCpu : 8 CpuTotalMhz : 19288 CpuUsageMhz : 1975 MemoryTotalMB : 32766 MemoryUsageMB : 11733 ProcessorType : Dual-Core AMD Opteron(tm) Processor 8216 HyperthreadingActive : False TimeZone : Europe/Zurich Version : 3.5.0 Build : 163429 CustomFields : {} Id : HostSystem-host-107 Name : 50001.domain.net PS M:\Documents\MyData\csv_scripts> get-vmhost 50001.domain.net | select -ExpandProperty ExtensionData Select-Object : Property "ExtensionData" cannot be found. At line:1 char:46 + get-vmhost 50001.domain.net | select <<<< -ExpandProperty ExtensionData + CategoryInfo : InvalidArgument: ( 50001.domain.net :PSObject) [Select-Object] , PSArgumentException + FullyQualifiedErrorId : ExpandPropertyNotFound,Microsoft.PowerShell.Commands.SelectObjectCom mand
You are probably using a pre-PowerCLI 4.1 build.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hi all,
Just to bring some clarification about using the filter parameter of the Get-View cmdlet. Inside the hash table you should provide name of properties that correspond to the actual manage object properties on the server. That include nested properties, not only first level ones. You can find out the properties of the objects in the API reference guide (yes, this is kind of advanced feature so it does require as Luc say "that extra step"). Some examples:
Get-View -ViewType HostSystem -Filter @{"name" = "MyHost"}
Get-View -ViewType HostSystem -Filter @{"runtime.powerState" = "poweredOn"} NB property names are case sensitive
Yavor,
PowerCLI team
Using filter parameter for Get-View is performance optimized but actually filtering is not done completely server side but these are implementation details so I will not bother you with them now.
Thanks for the info Yavor.
And yes, you are right, the filter accepts nested properties, contrary to what I first thought.
But do you agree that filtering on the MoRef with ViewType HostSystem seems to be indeed a bug ?
Seen that it does work for ViewType VirtualMachine and other managed objects.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Luc,
I'm not sure if I get your question correct. If you are pointing to the case:
Get-View -ViewType HostSystem -Filter @{"MoRef"="HostSystem-host-123"}
I don't think this is a bug, since "MoRef" is not a property of the managed object HostSystem. Actually it is not a property, I should clarify a name of a property of any managed object on the server. About seeing it working for virtual machines: that is the part that brings doubts in me whether I understand you question correctly. If we change HostSystem with VirtualMachine in the above example, I don't see how that will work.
Yavor,
PowerCLI team