Foreach

From UVOO Tech Wiki
Revision as of 15:15, 25 April 2022 by Busk (talk | contribs) (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...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

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 }
   }

}