Hi All;
Recently an interesting case came in front of me, and i am not able to find any simple solution for it..
Ok; heres the case
I have a VMname but i don't know whether its a vCenter Name of that VM or the DNS name i.e. Guest.HostName. so if i have to get this VM using get-view i have to run same command with different properties;
my question is - Is there any way i can combine these two properties??? like we do and operation as follows
$Vmname= Get-View -ViewType VirtualMachine -Property Name -Filter @{“Name”=”^MyVmName$”; “Guest.hostName”=”^MyVmName$”}
Above line will return vm object if both the conditions satisfy; but i want any one property to filter. with get-view.
$Vmname= Get-View -ViewType VirtualMachine -Property Name -Filter @{“Name”=”^MyVmName$” ??? “Guest.hostName”=”^MyVmName$"} ???
is there any way to replace those question-marks in Filter array and get desire output..
Regards
Sanshis
-Filter <Hashtable>
Specifies a hash of <name>-<value> pairs, where <name> represents the property value to test, and <value> represents a regex pattern the
property must match. If more than one pair is present, all the patterns must match.
get-view -ViewType virtualmachine -Property name,guest.hostname |?{$_.Name -eq 'name1' -or $_.Guest.Hostname -eq 'sth'}
Thx Grzesiekk for your reply.
but this will be a very slow process and environment having 12K VMs this is not useful . i was looking for something quick. currently i am doing with if else ladder and it seem that's the best way.
Regards
Sanshis
Have you measured the time it takes to run: get-view -viewtype virtualmachine -property name,guest.hostname ? Even with 12k vms , that should not take longer than i guess 30 seconds,