locked
Replace a string RRS feed

  • Question

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

    Sunday, October 5, 2014 3:15 PM

Answers

  • I modified the script with C:\Users\*\AppData\ and it works.


    Sunday, October 5, 2014 5:33 PM

All replies

  • Can you explain what exactly it is you're trying to do with the script, and also what is actually happening currently? Working it out from the script is hard enough, but since the script obviously doesn't do what you're looking for it's even harder to guess what might be wrong with it!
    Sunday, October 5, 2014 4:46 PM
  • Hi Keith

    I must modify an IP of a ini file for those who have profiles:

    C:\users\profile01\AppData\Dir\file.ini

    C:\users\profile02\AppData\Dir\file.ini

    C:\users\profile03\AppData\Dir\file.ini

    Sunday, October 5, 2014 4:50 PM
  • I modified the script with C:\Users\*\AppData\ and it works.


    Sunday, October 5, 2014 5:33 PM