Updating the contents of multiple files

I'm using transform manager to auto-generate some HTML files for us and we need to change one line in each of those files. The code I'm using to change one of them is:

get-childitem default.html |
Get-Content |
ForEach-Object {$_ -replace "<AutoPlay>false</AutoPlay>", "<AutoPlay>true</AutoPlay>"} |
Set-Content default.html

Fairly simple. But when I try to loop through all the default.html files (there's one in each subdirectory):

$Files = Get-ChildItem -Path C:\inetpub\wwwroot -Name default.html -Recurse

foreach ($File in $Files) {
write-host "Updating $($File.fullname)..."
sleep 5
(Get-Content $file.fullname) | 
ForEach-Object {$_ -replace "<AutoPlay>false</AutoPlay>", "<AutoPlay>true</AutoPlay>"} | 
Set-Content $file.fullname
}

I seem to getting something strange back from the Get-ChildItem. The response is "Updating ...". Then it complains about the filename property. You guys see anything wrong here?

Thanks.

July 23rd, 2013 11:00am

Please post the exact error message.

Bill

Free Windows Admin Tool Kit Click here and download it now
July 23rd, 2013 11:03am

Instead of " -Name default.html " you need to use " -Include default.html " the -Name switch tells the Get-ChildItem function to return only names, -Include filters the results.

Good luck!


July 23rd, 2013 11:24am

Gah! That was exactly it. Thanks Brian. Just needed another pair of eyes.
Free Windows Admin Tool Kit Click here and download it now
July 24th, 2013 12:29pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics