I have a script which looks like below:-
$AllVMs = Get-View -ViewType VirtualMachine -Filter @{"Name" = "view-L02"}
Capability : VMware.Vim.VirtualMachineCapability
Config : VMware.Vim.VirtualMachineConfigInfo
Layout : VMware.Vim.VirtualMachineFileLayout
LayoutEx : VMware.Vim.VirtualMachineFileLayoutEx
Storage : VMware.Vim.VirtualMachineStorageInfo
EnvironmentBrowser : EnvironmentBrowser-envbrowser-120766
ResourcePool : ResourcePool-resgroup-112616
ParentVApp :
ResourceConfig : VMware.Vim.ResourceConfigSpec
Runtime : VMware.Vim.VirtualMachineRuntimeInfo
Guest : VMware.Vim.GuestInfo
Summary : VMware.Vim.VirtualMachineSummary
Datastore : {Datastore-datastore-108956, Datastore-datastore-108965,
Datastore-datastore-108969}
Network : {Network-network-107087}
Snapshot : VMware.Vim.VirtualMachineSnapshotInfo
RootSnapshot : {VirtualMachineSnapshot-snapshot-120767}
GuestHeartbeatStatus : green
Parent : Folder-group-v106553
CustomValue : {}
OverallStatus : green
ConfigStatus : green
ConfigIssue : {}
EffectiveRole : {1}
Permission : {}
Name : view-L02-209
DisabledMethod : {Destroy_Task, UnregisterVM, UnmountToolsInstaller, Answ
erVM...}
RecentTask : {}
DeclaredAlarmState : {alarm-152.vm-120766, alarm-153.vm-120766, alarm-155.vm-
120766, alarm-156.vm-120766...}
TriggeredAlarmState : {}
AlarmActionsEnabled : True
Tag : {SYSTEM/COM.VMWARE.SIM.SVILINKEDCLONE}
Value : {}
AvailableField : {Transfer Server Status, VM Lock Status, View Local Mode
Status}
MoRef : VirtualMachine-vm-120766
Client : VMware.Vim.VimClient
Next line in script:-
$SortedVMs = $AllVMs | Select *, @{N="NumDisks";E={@($_.Guest.Disk.Length)}} | Sort-Object -Descending NumDisks
Where will the script find information for Guest.Disk.Length? Is it found as part of Get-View -Viewtype. I guess I have to read some documentation for Vsphere for PowerCLI to understand this. Any help is appreciated.
You have to understand that PowerShell works with objects.
In this case the Get-View returned an object of the type VirtualMachine.
The property Guest.Disk is in fact an array of objects and PowerShell has an builtin property for each array which is called Length.
This builtin property returns the number of elements in the array, in other words the number of disk connected to the guest.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hello, MeghaManohar-
From the result of the first command, you see the properties of the VM's .Net View object. The first column holds the property names, and the second hold their values. You can see what properties are available via the API. The "Guest" property, has a value of type "VMware.Vim.GuestInfo":
...
Guest : VMware.Vim.GuestInfo
...
So, the value is not a string, but rather another object. This object has other properties, one of which is "Disk". From the GuestInfo API link above, you can see that Disk is an array.
So, getting "$_.Guest.Disk.Length", the next part of the script that you mentioned is getting the length of the array of Disk objects, which effectively gets the Disk count, labeled as "NumDisks" in your example in the "calculated property".
Make sense?
Edited by mattboren: Doh -- I see that the omnipresent LucD has already answered...
No problem, two explanations is always better than one
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thank you LucD for the explanation.
Thank you Mattboren for the explanation