Quantcast
Channel: The Official Scripting Guys Forum! forum
Viewing all articles
Browse latest Browse all 15028

Replace a string

$
0
0

Hi 

I have this script but not working. 
I need to loop through all the profiles c:\users\* and when you find the "config.ini" file which is usually C:\users\profile01\AppData\Dir modifies a string by another value.

$path = "C:\Users"

get-childitem "$Path" -include *.ini -recurse |
foreach-Object{
        if((Get-Content $_) -match '192.168.1.1'){
                "$_" | Out-File "$Path\config.ini" -Append -Force -NoClobber
                 (Get-Content $_) |
                 Foreach-Object {$_ -replace '192.168.1.1', '172.20.1.1'} |
                 Set-Content $_
         }
}


Viewing all articles
Browse latest Browse all 15028

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>