Custom Objects & Export-CSV

I’m working on a report for VM info from both vCenter and SCVMM. I want data in a CSV so I can eventually put it into PowerBI.

To get the raw data I need I’m simply getting all hosts in the SCVMM env

$hypervHosts = Get-SCVMHostCluster 

I’m then building a custom object to get the values that I want.

$hyperv = New-Object -TypeName PSObject $hyperv | Add-Member -MemberType NoteProperty -Name Name -Value $hypervHosts.nodes.vms.name $hyperv | Add-Member -MemberType NoteProperty -Name Datastore -Value $hypervHosts.nodes.vms.location $hyperv | Add-Member -MemberType NoteProperty -Name Application -Value $hypervHosts.nodes.vms.customproperty.values $hyperv | Add-Member -MemberType NoteProperty -Name 'Virtualization Platform' -Value $hypervHosts.nodes.vms.virtualizationplatform $hyperv | Add-Member -MemberType NoteProperty -Name UsedSpaceGB -Value 'test' $hyperv | Add-Member -MemberType NoteProperty -Name "Num CPU" -Value $hypervHosts.nodes.vms.cpucount $hyperv | Add-Member -MemberType NoteProperty -Name MemoryMB -Value .nodes.vms.memory $hyperv | Add-Member -MemberType NoteProperty -Name PowerState -Value $hypervHosts.nodes.vms.status $hyperv | Add-Member -MemberType NoteProperty -Name HardwareVersion -Value $hypervHosts.nodes.vms.generation 

Eventully the idea is to use powerCLI to add to this object.

UsedSpaceGB : test Num CPU : {8, 4, 2, 1, 2, 1, 2, 4, 2, 2, 4, 8, 1, 2, 3, 2, 4, 2, 4, 4, 4, 4, 4, 1, 2, 2, 12, 4, 12, 2, 2, 2, 2, 2, 4, 1, 4, 2, 4, 4, 1, 4, 4, 2, 2, 4, 3, 4, 2, 1, 6, 8, 4, 8, 4, 16, 4, 2, 4, 8, 2, 4, 2, 2, 2, 4, 3, 8, 3, 4, 4, 8, 1, 4, 1, 4, 2, 4, 8, 6, 4, 4, 4, 8, 4, 1, 4, 6, 4, 4, 12, 2, 4, 3, 3, 4, 2, 2, 2, 1, 1, 1, 2, 4, 2, 2, 2, 1, 2, 1, 2, 2, 2, 2, 2, 2, 2, 4, 2, 2, 3, 4, 2, 3, 4, 2, 2, 2, 2, 1, 2, 2, 3, 4, 4, 3, 4, 2, 4, 8, 1, 1, 2, 2, 2, 2, 1, 2, 2, 4, 3, 8, 4, 2, 4, 6, 8, 2, 4, 1, 4, 2, 2, 2, 4, 2, 2, 4, 2, 4, 2, 2, 2, 4, 3, 4, 2, 2, 2, 2, 1, 4, 4, 2, 2, 2, 4, 2, 2, 4, 2, 2, 6, 2, 4, 4, 2, 2, 2, 2, 2, 2, 2, 2, 4, 2, 2, 4, 2, 2, 4, 4, 2, 2, 2, 2, 12, 6, 4, 2, 8, 4, 2, 2, 8, 4, 4, 2, 2, 4, 8, 4, 4, 4, 8, 4, 2, 4, 8, 4, 8, 2, 2, 2, 2, 2, 2, 2, 2} MemoryMB : .nodes.vms.memory PowerState : {Running, Running, Running, Running, Running, Running, PowerOff, Running, Running, Running, Running, Running, Running, Running, Running, Running, PowerOff, Running, Running, Running, Running, Running, Running, Running, Running, PowerOff, Running, Running, Running, Running, Running, Running, Running, Running, Running, Running, Running, Running, Running, Running, Running, Running, Running, Running, Running, Running, Running, Running, Running, Running, Running, Running, Running, Running, Running, Running, Running, Running, Running, Running, Running, Running, Running, Running, Running, Running, Running, Running, Running, Running, Running, Running, Running, Running, Running, Running, PowerOff, Running, Running, Running, Running, Running, Running, Running, Running, Running, Running, Running, Running, Running, Running, Running, Running, Running, Running, Running, Running, Running, Running, Running, Running, Running, Running, Running, Running, Running, Running, Running, Running, Running, Running, Running, Running, Running, Running, Running, Running, Running, Running, Running, Running, Running, Running, Running, Running, Running, Running, Running, Running, Running, Running, Running, Running, Running, Running, Running, Running, Running, Running, Running, Running, Running, Running, PowerOff, Running, Running, Running, Running, Running, Running, Running, Running, Running, Running, Running, Running, Running, Running, Running, Running, Running, Running, Running, Running, Running, Running, Running, Running, Running, Running, Running, Running, Running, Running, Running, Running, Running, Running, Running, Running, Running, Running, Running, Running, Running, Running, Running, Running, Running, Running, Running, Running, Running, Running, Running, Running, Running, Running, Running, Running, Running, Running, Running, Running, Running, Running, Running, Running, PowerOff, Running, Running, Running, Running, Running, Running, PowerOff, Running, Running, Running, Running, Running, Running, Running, Running, Running, Running, Running, Running, Running, Running, Running, PowerOff, Running, Running, Running, Running, Running, Running, Running, Running, Running, Running, Running, Running, Running, Running, Running, Running, PowerOff} HardwareVersion : {2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 2, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, 1, 2, 1, 2, 1, 2, 2, 2, 2, 1, 2, 2, 2, 2, 1, 2, 2, 1, 2, 2, 2, 2, 2, 1, 2, 2, 2, 2, 2, 1, 2, 2, 1, 1, 1, 2, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2} 

The results look like that in the console.

Name Datastore Application Virtualization Platform UsedSpaceGB Num CPU MemoryMB PowerState HardwareVersion System.Object[] System.Object[] System.Object[] System.Object[] test System.Object[] .nodes.vms.memory System.Object[] System.Object[] 

CSV file looks like this.

Want I want is something like this.

Name Datastore Application Virtualization Platform UsedSpaceGB Num CPU MemoryMB PowerState HardwareVersion servername1 nimblelun1 voice hyperv 4939 2 2048 running 2 servername2 nimblelun2 vdi esk 384 4 4098 running 2 

I’ve been staring at this to long and feel like I’m stuck in a bad logic loop and need some assistance.

submitted by /u/linuxape
[link] [comments]

Leave a Reply