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.
This topic is 3 years and 2 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
sekou2331
Posts: 318
Last visit: Sat Oct 28, 2023 7:46 am

INI file

Post by sekou2331 »

Is there a CMDLET that can add a section to an INI file?
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

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: 318
Last visit: Sat Oct 28, 2023 7:46 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: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: INI file

Post by jvierra »

User avatar
sekou2331
Posts: 318
Last visit: Sat Oct 28, 2023 7:46 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: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

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: 318
Last visit: Sat Oct 28, 2023 7:46 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: 8472
Last visit: Mon Mar 18, 2024 2:59 pm
Answers: 19
Been upvoted: 37 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: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: INI file

Post by jvierra »

You can't break an ini file by adding a section.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

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
This topic is 3 years and 2 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked