$SQLVMs = (Get-ITDVMwareSharePointVMGuestList | Where-Object { $_.LicensingRestrictions -like "*SQL*" -and $_.Status -ne "Deleted" }).Title | Sort-object $result = [System.Collections.ArrayList]@() ForEach ($SQLVM in $SQLVMs) { $VM = $null $Disks = $null $PersistentDisks = $null $IndPersistentDisks = $null $VM = Get-VM -Name $SQLVM | Where-Object { $_.ExtensionData.summary.config.ManagedBy.Type -ne "placeholderVm" } If ($VM) { $Disks = $vm | Get-HardDisk $PersistentDisks = $Disks | where-object Persistence -eq Persistent $IndPersistentDisks = $Disks | Where-Object Persistence -eq IndependentPersistent $obj = [PSCustomObject]@{ 'Name' = $VM.Name; 'DisksPersistentCount' = @($PersistentDisks).count 'DisksPersistentSizeGB' = ($PersistentDisks | measure-object -Sum CapacityGB).Sum 'DisksIndPersistentCount' = @($IndPersistentDisks).count 'DisksIndPersistentSizeGB' = ($IndPersistentDisks | measure-object -Sum CapacityGB).Sum } $null = $result.Add($obj) } }