I'm doing a number of string replacements in a PowerShell script.
foreach ($file in $foo) {
$outfile = $outputpath + $file
$content = Get-Content ($file.Fullname) -replace 'foo','bar'
Set-Content -path $outfile -Force -Value $content
}
I've validated (through console logging of $outfile and $content, which I don't show in the above code) that the proper files are being selected, the -replace is accuratly updating the content, and the $outfiles are being created. However, each of the output files a 0 byte file. The Set-Content line does not appear to be writing the data to the files. I've tried piping Set-Content to Out-File, but that just gives me an error.
When I replace Set-Content with Out-File, I get a runtime error Out-File : A parameter cannot be found that matches parameter name 'path'. even though I can output $outfile to the console and see that it's a valid path.
Is there an additional step (like a close-File or save-file command) I need to take or a different order in which I need to pipe something to get the $content to write to my $outfile? What component am I missing?
-replaceis accurately modifying the contents when I log$contentto the console...