$Result = [System.Collections.ArrayList]@() $VMHosts = Get-VMHost ForEach ($VMHost in $VMHostNames) { $EsxCli = Get-EsxCli -VMHost $VMHost -V2 $Settings = $EsxCli.system.settings.encryption.get.invoke() If ($Settings.Mode -eq "TPM") { $list = $EsxCli.system.settings.encryption.recovery.list.invoke() $obj = [PSCustomObject]@{ 'Name' = $VMHost 'Key' = $list.Key 'RecoveryId' = $list.RecoveryId } $null = $Result.Add($obj) } else { $obj = $null $list = $null } }