INI file

Ask your PowerShell-related questions, including questions on cmdlet development!
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
User avatar
sekou2331
Posts: 309
Joined: Wed Aug 15, 2012 6:07 am

INI file

Post by sekou2331 »

Is there a CMDLET that can add a section to an INI file?

jvierra
Posts: 14677
Joined: Tue May 22, 2007 9:57 am
Answers: 6
Has voted: 1 time
Been upvoted: 5 times
Contact:

Re: INI file

Post by jvierra »

You can download INI file managers from PowerShellGet. Three are a few. Pick the one that suits your needs.

User avatar
sekou2331
Posts: 309
Joined: Wed Aug 15, 2012 6:07 am

Re: INI file

Post by sekou2331 »

Do you have one you suggest? I tried a couple and they seem to be not working

jvierra
Posts: 14677
Joined: Tue May 22, 2007 9:57 am
Answers: 6
Has voted: 1 time
Been upvoted: 5 times
Contact:

Re: INI file

Post by jvierra »


User avatar
sekou2331
Posts: 309
Joined: Wed Aug 15, 2012 6:07 am

Re: INI file

Post by sekou2331 »

I am looking at this and I don't know if I am reading it right but this just reads the INI file and output it to as a hash. I just want to add a section to an existing ini file without damaging it.

jvierra
Posts: 14677
Joined: Tue May 22, 2007 9:57 am
Answers: 6
Has voted: 1 time
Been upvoted: 5 times
Contact:

Re: INI file

Post by jvierra »

To add a section just create the text and add it to the file at the end.

User avatar
sekou2331
Posts: 309
Joined: Wed Aug 15, 2012 6:07 am

Re: INI file

Post by sekou2331 »

I have to do it to multiple files and worried if I just add I will break the ini file in some way.

User avatar
Alexander Riedel
Posts: 7565
Joined: Tue May 29, 2007 4:43 pm
Answers: 2
Been upvoted: 5 times

Re: INI file

Post by Alexander Riedel »

It's just a text file. You can't be afraid of the wind. Just iterate through your files and append the section you want to the end. Probably want to make sure you add a CR/LF before adding your stuff.
Alexander Riedel
SAPIEN Technologies, Inc.

jvierra
Posts: 14677
Joined: Tue May 22, 2007 9:57 am
Answers: 6
Has voted: 1 time
Been upvoted: 5 times
Contact:

Re: INI file

Post by jvierra »

You can't break an ini file by adding a section.

jvierra
Posts: 14677
Joined: Tue May 22, 2007 9:57 am
Answers: 6
Has voted: 1 time
Been upvoted: 5 times
Contact:

Re: INI file

Post by jvierra »

Easiest way is:

Code: Select all

$section = @'
	item1=text1
    item2=text2
    item3=text2
'@

$section | Out-File file.ini -Append 
All else will be taken care of automatically

Post Reply