This is also relatively easy to accomplish with a regex.
$hosts = Get-Content .\hostfile.txt foreach ($computer in $hosts) { $computer -match '-host "(?<hostname>.*?)"' | Out-Null $Matches['hostname'] }
I will also echo Dave’s comments about the quote marks in the original post. The above works with standard quotes (ASCII 34).