none
Add a couple of line to an INI file using powershell RRS feed

  • Question

  • Hi,

    I have an INI file which has a lot of sections, and I'm trying to update it with powershell to add a couple of lines to a particular section

    [Section 1]

    myamendment1=1

    myamendment2=2

    I can't find a PS cmdlet to do this, and I can't get a couple of examples I have seen to work.

    Has got any working examples?

    Thanks


    Jaz

    Monday, March 13, 2017 10:17 PM

Answers

  • $iniFile='c:\scripts\test.ini' 
    $sections = [ProfileAPI]::GetSectionNames($iniFile
    [ProfileAPI]::GetSection($iniFile,'section 1'| ConvertFrom-StringData 

    [profileapi]::WritePrivateProfileString('section 1''myammendment1''1',$iniFile


    \_(ツ)_/



    Tuesday, March 14, 2017 12:36 AM

All replies