Replace entire ini-section

Hi,

i have an *.ini config file for an 3rd party application, that has to be maintained whenever a Windows user login name changes - which happens after he or she switches the division within the department, gets married or divorced - or when he or she joins the or leaves the department.

With Sapien POSH Studio i’ve written a tool, that should be able to edit only the user section of this config file. So far i’m reading the section into a table and bind it to an editable gridview. I can change, add or remove lines.

I’ve thought a lot about changing single entries and so on, but thats to much fiddling because keys as well as values may change, be removed or added. Example:

[TerminalServerUser]
USR44WTH=8000HWTHA
USR447EEU=8000HEEUS

Now, how do I replace an entire section within the config file with the content of the table?

Thanks in advance for any input

Sascha

There are many solutions that talk about managing INI files with Powershell, for instance:

https://www.petri.com/managing-ini-files-with-powershell
https://devblogs.microsoft.com/scripting/use-powershell-to-work-with-any-ini-file/

Thanks Rob, but the general basics with ini files was not the question. I was asking if someone knows a faster way than removing each key one by one from the hash table’s section…

I was asking if someone knows a faster way than removing each key one by one from the hash table's section...

Here is a great blog on hashtables:

https://powershellexplained.com/2016-11-06-powershell-hashtable-everything-you-wanted-to-know-about/

Here is a something to start with:

$TerminalServerUser = @{}
$TerminalServerUser.Add('Param1', 'Value1')
$TerminalServerUser.Add('Param2', 'Value2')

$newStuff = @{}
$newStuff.Add('Param3', 'Value3')
$newStuff.Add('Param4', 'Value4')

$TerminalServerUser.Clear()

$TerminalServerUser = $newStuff.Clone()

$TerminalServerUser