Foreach
Jump to navigation
Jump to search
hosts.txt
host1.foo host2.foo
foo.ps1
$regex = "foo"
foreach($line in Get-Content .\hosts.txt) {
if($line -match $regex){
write-output $line
Invoke-Command -ComputerName "$line" -ScriptBlock { hostname }
}
}