Replace Content in File

This topic contains 1 reply, has 2 voices, and was last updated by Profile photo of Max Kozlov Max Kozlov 1 month, 2 weeks ago.

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #49987
    Profile photo of carl trevett
    carl trevett
    Participant

    Hi

    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
    Profile photo of Max Kozlov
    Max Kozlov
    Participant

    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
    
Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.