Hey all, hope you all have good Christmas/Holiday.
I’m creating a tool to capture data from vSphere for any of our VM’s so we have a point in time snapshot of the current set up prior to actioning any change on that VM. This data is exported to csv and attached to the change as part of the pre checks in case of roll back. I have sub tools that capture different elements of the VM (Hardware config, Storage config, IP config etc.) and want to combine them together in one object (if possible) so that we can then feed that info to other tools or exported to csv giving us one line per VM with all of its parts.
Now if the VM has one IP Address and one Hard Disk this is simple. I can create the one object and everyone is happy. However VMs can have multiple IPs and multiple disks. Below are the examples of the output for Server 1 (One Hard Disk), Server 2 (Three Hard Disks) and one non existent vm (bob) which outputs a blank object
##Basic VM info
PS C:\> Get-vSphereVMData -ComputerName server1,server2,bob VMName : server1 Status : True PowerState : PoweredOn vCpu : 2 MemoryGB : 4 Datastore : LUN01 VMXFile : [LUN01] server1/server1.vmx vCenter : vc01 Host : esx01.operations.local OS : Microsoft Windows Server 2012 (64-bit) VMName : server2 Status : True PowerState : PoweredOn vCpu : 4 MemoryGB : 12 Datastore : LUN01 VMXFile : [LUN01] server2/server2.vmx vCenter : vc01 Host : esx01.operations.local OS : Microsoft Windows Server 2012 (64-bit) vAppName : bob Status : False PowerState : vCpu : MemoryGB : Datastore : VMXFile : vCenter : Host : OS :
##Hard disk configuration per vm
PS C:\> Get-vSphereVMStorageData -ComputerName server1,server2,bob VM : server1 Status : True SCSI : 0:0 HD : Hard disk 1 Label : SCSI controller 0 SCSIType : LSI Logic Filename : [LUN01] server1/server1_1.vmdk CapacityGB : 64 VM : server2 Status : True SCSI : 0:0 HD : Hard disk 1 Label : SCSI controller 0 SCSIType : LSI Logic SAS Filename : [LUN01] server2/server2.vmdk CapacityGB : 60 VM : server2 Status : True SCSI : 0:1 HD : Hard disk 3 Label : SCSI controller 0 SCSIType : LSI Logic SAS Filename : [LUN01] server2/server2_2.vmdk CapacityGB : 100 VM : server2 Status : True SCSI : 1:0 HD : Hard disk 2 Label : SCSI controller 1 SCSIType : LSI Logic SAS Filename : [LUN01] server2/server2_1.vmdk CapacityGB : 200 WARNING: Errors happened when attempting to find VM bob in vc01 VM : bob Status : False SCSI : HD : Label : SCSIType : Filename : CapacityGB :
I’m foreaching through each disk and grabbing the data I need and outputting one object per disk. Server 1 has one disk, Serer 2 has three disks and bob does not exist.
The thing that is screwing with my head, is stitching the data together per server. Like i said above it’s easy when the VM has one disk but i can’t figure out how to handle if a VM has multiple disks. Looking at the the max number of disks a VM can have it can be up to 64 disks. (BTW this question is only looking at disks but i am also having the same problem with multiple IP/Network cards too). Am i going in the right direction with an expanding object (if that’s even possible) or am i diving down a Inception rabbit hole going the wrong direction?