Quantcast
Channel: PowerShell.org » All Posts
Viewing all articles
Browse latest Browse all 13067

Reply To: How to take specific words as objects from the text

$
0
0

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).


Viewing all articles
Browse latest Browse all 13067

Trending Articles