Please check:
$clusterResources
contains all VMs?
$x
is created and contains details for each VM?
If both is yes than $x
needs to be added to the csv file in every for-each loop.
Please try this:
$clusterResources = Get-ClusterResource -Cluster <ClusterName> | Where ResourceType -eq "Virtual Machine"
foreach ($clusterResource in $clusterResources) {
$x = Get-VM -Clusterobject $clusterResource |
Select-Object Name,MemoryStartup,MemoryMinimum,MemoryMaximum,DynamicMemoryEnabled,ProcessorCount
$vmObject = Get-VM -Clusterobject $clusterResource
$y = get-VMMemory -VM $vmObject
$x | Add-Member NoteProperty buffer $y.buffer
$x | Add-Member NoteProperty priority $y.priority
<#
$z = Get-VM -Computername (Get-ClusterNode) | where {$_.VMId -eq $vmObject.VMId} |
Get-VHD -VMId $_.VMId -ComputerName $_.ComputerName |
Select-Object path,size
$GreatestNumberOfPaths = 0
$z |
Foreach-Object{
if($_.Path.size -gt $GreatestNumberOfPaths){
$GreatestNumberOfPaths = $_.Path.Length
}
}
$GreatestNumberOfPaths -= 1
$z.Path |
ForEach-Object {$i=0}{
if ($GreatestNumberOfPaths -le $i){
$x | Add-Member NoteProperty ("Path[{0}]" -f ($i+1)) $z.Path[$i]
$x | Add-Member NoteProperty ("Size[{0}]" -f ($i+1)) $z.Size[$i]
}
Else{
$x | Add-Member NoteProperty ("Path[{0}]" -f ($1+1)) ""
$x | Add-Member NoteProperty ("Size[{0}]" -f ($1+1)) ""
}
$i++
}
#>
$x | Export-CSV c:\temp\VMInfo.csv -NoTypeInformation -Append
}
(If the reply was helpful please don't forget to upvote and/or accept as answer, thank you)
Regards
Andreas Baumgarten