Loop through files in a directory using PowerShell

Clippy
Messages : 22157
Inscription : mer. 22 avr. 2026, 17:33

Loop through files in a directory using PowerShell

Message par Clippy »

Loop through files in a directory using PowerShell
Clippy
Messages : 22157
Inscription : mer. 22 avr. 2026, 17:33

Re: Loop through files in a directory using PowerShell

Message par Clippy »

Give this a try:

```
Get-ChildItem "C:\Users\gerhardl\Documents\My Received Files" -Filter *.log |
Foreach-Object {
$content = Get-Content $_.FullName

#filter and save content to the original file
$content | Where-Object {$_ -match 'step[49]'} | Set-Content $_.FullName

#filter and save content to a new file
$content | Where-Object {$_ -match 'step[49]'} | Set-Content ($_.BaseName + '_out.log')
}

```
Répondre

Revenir à « PowerShell »