Hey guys, struggling a little on a script I’m trying to write that is meant to gather various stats across our environment into a single exec summary report and am hoping someone here could shed a little light on how to accomplish what I’m trying to accomplish.
I have two separate pieces, one that collects vmware stats and one that collects netapp stats. Here is my code for that:
Connect-VIServer -Server vcenter1, vcenter2
$myVCCol = @()
foreach($cluster in (get-cluster | sort Name)){
$ClusterVMs = $Cluster | Get-VM
$ClusterCPUCores = $Cluster.ExtensionData.Summary.NumCpuCores
$ClusterAllocatedvCPUs = ($ClusterVMs | Measure-Object -Property NumCPu -Sum).Sum
$ClusterEffectiveMemoryGB = [math]::round(($Cluster.ExtensionData.Summary.EffectiveMemory / 1KB),0)
$ClusterAllocatedMemoryGB = [math]::round(($ClusterVMs | Measure-Object -Property MemoryMB -Sum).Sum / 1KB)
$vcstats = New-Object -TypeName psobject -Property @{
date = Get-Date -Format ddMMyyyy
cluster = $cluster.Name
clustercores = $ClusterCPUCores
clusterassignedcores = $ClusterAllocatedvCPUs
clusterram = $ClusterEffectiveMemoryGB
clusterassignedram = $ClusterAllocatedMemoryGB
}
$vcstats = $vcstats | select date, cluster, clustercores, clusterassignedcores, clusterram, clusterassignedram
$myvccol += $vcstats
}
$nacs = “nac1”,“nac2”
$myNACol = @()
foreach($nac in $nacs){
Connect-NcController $nac -Credential $creds
$filerTtl = 0
$filerAvail = 0
$filerUsed = 0
foreach($aggr in (get-ncaggr | sort name)){
$aggrTtl = [math]::Round($aggr.TotalSize / 1TB, 2)
$aggrAvail = [math]::Round($aggr.Available / 1TB, 2)
$aggrUsed = $aggrTtl - $aggrAvail
$filerttl += $aggrTtl
$filerAvail += $aggrAvail
$filerUsed += $aggrUsed
}
$nastats = New-Object -TypeName psobject -Property @{
date = Get-Date -Format ddMMyyyy
filer = $nac
filerttlspaceTB = $filerTtl
filerusedspaceTB = $filerUsed
fileravailspaceTB = $filerAvail
}
$nastats = $nastats | select date, filer, filerttlspaceTB, filerusedspaceTB, fileravailspaceTB
$myNACol += $nastats
}
Both the $myVCCol and $myNACol objects are reporting all the data I need correctly, I’m just struggling on how to get them together into a single object that I can then send in a single table via an html email (much praise to Milo for their send-htmlemail function).
I’m no powershell expert (as is probably apparent by my code
) but I’ve tried stuff like $myVCCol += $myNACol and $mycols = $myVCCol, $myNCCol and doing a foreach loop to populate a new object, but neither is giving me my desired results.
Something tells me I’m missing something obvious but for whatever reason, I just can’t seem to figure it out. Any pointers?