Author Posts

August 11, 2016 at 10:41 am

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 $_
}

August 11, 2016 at 11:13 am

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