Scripting Question

Replace Lini in ini with Powershell

07/28/2020 119 views


I have to deaktivate a line in an ini File. It is justr adding an ; at the beginning.

I tried to replace it real simpel, but getting an Error. What am I doing wrong? 




         # Deaktivieren von NXPowerlite

          [string[]]$ProfilePaths = Get-UserProfiles -ExcludeNTAccount 'Domain\accountname' | Select-Object -ExpandProperty 'ProfilePath'

        foreach  ($Profile in $ProfilePaths){

            (Get-Content -Path "$NotesINI\notes.ini") -replace "$alterEintrag", "$neuerEintrag" | Set-Content "$NotesINI\notes.ini"             



0 Comments   [ + ] Show comments


Community Chosen Answer








NotesProgram=c:\Program Files (x86)\IBM\Lotus\Notes\





FaultRecovery_Build=Release 9.0.1FP10 SHF68






Answered 07/29/2020 by: av1gj
Senior White Belt

  • OK, that was easy. Sorry, i couldn't read your error message, but I think the error would of been "The regular expression pattern AddinMenus=C:\PROGRA~1\NXPOWE~1\NXPMEN~1.DLL is not valid."

    The PowerShell "replace" operator your using can also be used with Regular Expression. Because of that feature, your replace string is getting confused with the backslash's. You need to escape the backslash's for the pattern (search and replace) string to work.

    Fix below, use the simple test below to double check it works before adding it to your script.


    (Get-Content -Path "C:\A\Test.ini") -replace "$alterEintrag", "$neuerEintrag" | Set-Content "C:\A\Test.ini"

    Don't forget to check the encoding is the same before editing the file, and after editing the file, as mentioned in my post.

All Answers


Presuming the PowerShell script worked, and the file was successfully written with the desired changes?

The next step would be to check the file encoding is correct. For example open the INI that has not been modified in NotePad++ and check the encoding. 


Also dont forget to check hidden characters for the correct carrge return etc.


PowerShell Set-Content info https://ss64.com/ps/set-content.html

Check/read Encoding section for more information about switch


When editing files with scripting, always check with Notepad++ or your choice of editor for the correct file encoding and characters before and after a file change.

Answered 07/28/2020 by: rileyz
Red Belt


I believe that the following line is incorrect.

$neuerEintrag= ' ;

Should be

$neuerEintrag= ; '

Answered 07/28/2020 by: KevinG
6th Degree Black Belt

  • Ich want to replace the original Value with ; at the Beginning. So that cant be the Problem. I assume the special Characters are the Problem. Can you tell me, how I work with the Line as plain Text?

I found out, that it musst be something with the special charcters.

If I just  use the beginning, it works. 



Can you help me with the special Charcters?

Answered 07/29/2020 by: av1gj
Senior White Belt

  • Can you post a sample of the INI file for me to test, will see if I can fix it for you.
This website uses cookies. By continuing to use this site and/or clicking the "Accept" button you are providing consent Quest Software and its affiliates do NOT sell the Personal Data you provide to us either when you register on our websites or when you do business with us. For more information about our Privacy Policy and our data protection efforts, please visit GDPR-HQ