Click here to Skip to main content
15,888,286 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have an INI file :

[Participant]
Kids=1000
Adult=200

[Gender]
Female=100
Male=200

I want to edit the value of section participant which is Kids to be 500


What I have tried:

I tried this code, but it return an error

Cannot index into a null array.


$input_file = Get-Content "C:\Users\testing.ini"
$input_file["Participant"]["Kids"]="500"
$input_file | Out-IniFile -Force -FilePath "C:\Users\testing.ini"
Posted
Updated 24-Mar-19 22:33pm

If you notice,
$input_file = Get-Content "C:\Users\testing.ini"
just gets the content as a string. It outputs that as simply
[Participant] Kids=1000 Adult=200  [Gender] Female=100 Male=200


I'd suggest you look at using

Script Get-IniContent[^]

Which kinda looks like what you were trying to do but Im going to guess, you got an error saying something like "is not a cmdlet" or whatever the error is.

You'll probably need to look at this script also.

Script Out-IniFile[^]
 
Share this answer
 
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900