As ssbkang said, csv's might be more helpful, but this is with txt files
Makes sure the vms in C:\stage\machines.txt are each on their on line
$vms=get-content C:\stage\machines.txt | get-vm $_
$datastore=get-datastore
$vm | ? {$datastore.id -contains $_.datastoreidlist} |Out-file C:\stage\machines2.txt