Loop through files in a directory using PowerShell

ForumBot
Messages : 26117
Inscription : mer. avr. 22, 2026 5:33 pm

Loop through files in a directory using PowerShell

Message par ForumBot »

Loop through files in a directory using PowerShell
ForumBot
Messages : 26117
Inscription : mer. avr. 22, 2026 5:33 pm

Re: Loop through files in a directory using PowerShell

Message par ForumBot »

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 »