PowerShell
A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
2,449 questions
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Hello,
Pls
How replace txt :
cls
# start as admin
$FileList = Get-ChildItem -path "C:\MMC\*" | select FullName
$FileList | ForEach-Object {
Get-Content $_.FullName -replace ("old-txt", "new-txt") | Set-Content $_.FullName
}
Thank for your help
Arnold
As you've discovered, "-replace" isn't a parameter accepted by the Get-Content cmdlet. A pair of parentheses will fix that. Now "-replace" will operate on the list returned by Get-Content.
Get-ChildItem -path "C:\MMC\*" |
ForEach-Object {
(Get-Content $_.FullName) -replace ("old-txt", "new-txt") |
Set-Content $_.FullName
}
Sir,
Many thank!
Arnold