<t>Not much documentation on PowerShell loops.<br/>
<br/>
Documentation on loops in PowerShell is plentiful, and you might want to check out the following help topics: about_For, about_ForEach, about_Do, about_While.<br/>
<br/>
foreach($line in Get-Content .\file.txt) {<br/>
if($line -match $regex){<br/>
# Work here<br/>
}<br/>
}<br/>
<br/>
```<br/>
<br/>
Another idiomatic PowerShell solution to your problem is to pipe the lines of the text file to the [`ForEach-Object` cmdlet](https://learn.microsoft.com/en-gb/powershell/module/Microsoft.PowerShell.Core/ForEach-Object):<br/>
<br/>
```<br/>
Get-Content .\file.txt | ForEach-Object {<br/>
if($_ -match $regex){<br/>
# Work here<br/>
}<br/>
}<br/>
<br/>
```<br/>
<br/>
Instead of regex matching inside the loop, you could pipe the lines through [`Where-Object`](https://learn.microsoft.com/en-gb/powershell/module/Microsoft.PowerShell.Core/Where-Object) to filter just those you're interested in:<br/>
<br/>
```<br/>
Get-Content .\file.txt | Where-Object {$_ -match $regex} | ForEach-Object {<br/>
# Work here<br/>
}<br/>
<br/>
```</t>