/build/static/layout/Breadcrumb_cap_w.png

Replace Lini in ini with Powershell

Hi!! 


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? 


$NotesINI="$Profile\AppData\Local\Lotus\Notes\Data"    


        $alterEintrag='AddinMenus=C:\PROGRA~1\NXPOWE~1\NXPMEN~1.DLL'

        $neuerEintrag=';AddinMenus=C:\PROGRA~1\NXPOWE~1\NXPMEN~1.DLL'   

         # 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"             

        }


n+7W+cVhgoFFwAAAABJRU5ErkJggg==


0 Comments   [ + ] Show comments

Answers (4)

Posted by: av1gj 4 years ago
Senior White Belt
1

[Notes]

KitType=1

SharedDataDirectory=C:\ProgramData\Lotus\Notes\Data\Shared

UserInterface=de

InstallType=6

InstallMode=1

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

Configfile=C:\ProgramData\Lotus\Notes\Data\notescfg.txt

IM_DISABLED=1

IM_NO_SETUP=1



Directory=C:\Users\av1gj\AppData\Local\Lotus\Notes\Data

FaultRecovery_Build=Release 9.0.1FP10 SHF68

DSTLAW=3,-1,1,10,-1,1

USING_LOCAL_SHARED_MEM=1

LOCAL_SHARED_MEM_SESSION_ID=2

FileDlgDirectory=C:\Users\av1gj\Documents

AddinMenus=C:\PROGRA~1\NXPOWE~1\NXPMEN~1.DLL


Comments:
  • 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.

    $alterEintrag='AddinMenus=C:\\PROGRA~1\\NXPOWE~1\\NXPMEN~1.DLL'
    $neuerEintrag=';AddinMenus=C:\PROGRA~1\NXPOWE~1\NXPMEN~1.DLL'

    (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. - rileyz 4 years ago
Posted by: rileyz 4 years ago
Red Belt
0

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. 

EyB9FEABFEABFJhX4H8KjQlTuRIJ1AAAAABJRU5ErkJggg==


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

+AAAAAElFTkSuQmCC



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

Check/read Encoding section for more information about switch




Summary

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.

Posted by: KevinG 4 years ago
Red Belt
0

I believe that the following line is incorrect.


$neuerEintrag= ' ;

Should be

$neuerEintrag= ; '



Comments:
  • 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? - av1gj 4 years ago
Posted by: av1gj 4 years ago
Senior White Belt
0

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


If I just  use the beginning, it works. 

$alterEintrag="AddinMenus"

$neuerEintrag=';AddinMenus'


Can you help me with the special Charcters?


Comments:
  • Can you post a sample of the INI file for me to test, will see if I can fix it for you. - rileyz 4 years ago

Don't be a Stranger!

Sign up today to participate, stay informed, earn points and establish a reputation for yourself!

Sign up! or login

View more:

Share

 
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