Replace Content in File

This topic contains 1 reply, has 2 voices, and was last updated by  Max Kozlov 1 year, 11 months ago.

  • Author
  • #49987

    carl trevett


    I am trying to replace content within in multiple files on each server across multiple servers. I can get it to work local (so multiple files on one server). When I try the same thing via UNC path it falls apart on me, can anyone please help? or is it not possible and it needs to be completed with Invoke-Command?

    $Files = Get-ChildItem '\\server\i$\SecureInet\wwwroot\view' -Recurse -Depth 1 |
        Where-Object {$_.Name -eq 'web.config' -and $_.Directory -notlike '*Authentication*'}
        ForEach ($File in $Files) {(Get-Content $File | Forach { $_ -replace "OldValue","NewValue"}) |
        Set-Content $_
  • #49989

    Max Kozlov

    What kind of error you get ?
    are you sore that there is no error ? I think there is

    Get-Content $File | Forach { $_ -replace "OldValue","NewValue"}) |
        Set-Content $_

    should be

    Get-Content $File | Forach { $_ -replace "OldValue","NewValue"}) |
        Set-Content $File

You must be logged in to reply to this topic.