Difference between revisions of "Foreach"
Jump to navigation
Jump to search
(Created page with "hosts.txt ``` host1.foo host2.foo ``` $regex = "foo" foreach($line in Get-Content .\hosts.txt) { if($line -match $regex){ write-output $line Invoke-Comman...") |
(No difference)
|
Revision as of 15:15, 25 April 2022
hosts.txt
host1.foo host2.foo
$regex = "foo" foreach($line in Get-Content .\hosts.txt) {
if($line -match $regex){ write-output $line Invoke-Command -ComputerName "$line" -ScriptBlock { hostname } }
}