# Replace entire ini-section

**URL:** https://forums.powershell.org/t/replace-entire-ini-section/13411
**Category:** PowerShell Help
**Created:** [November 13, 2019, 7:19am UTC](https://forums.powershell.org/t/replace-entire-ini-section/13411 "2019-11-13T07:19:14Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![progenit0r](https://avatars.discourse-cdn.com/v4/letter/p/a183cd/32.png) [@progenit0r](https://forums.powershell.org/u/progenit0r)
#### Post date: [November 13, 2019, 7:19am UTC](https://forums.powershell.org/t/replace-entire-ini-section/13411/1 "2019-11-13T07:19:14Z")

</div>

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

---

<div class="post-metadata">

### Author: ![rob-simmers](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/rob-simmers/32/1010_2.png) [@rob-simmers](https://forums.powershell.org/u/rob-simmers)
#### Post date: [November 13, 2019, 11:05am UTC](https://forums.powershell.org/t/replace-entire-ini-section/13411/2 "2019-11-13T11:05:33Z")

</div>

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

> **[Managing INI Files with PowerShell | Petri IT Knowledgebase](https://petri.com/managing-ini-files-with-powershell/)**
>
> Jeff Hicks shows us how to manage traditional INI files in a more object-based approach with PowerShell.

> **[Use PowerShell to Work with Any INI File](https://devblogs.microsoft.com/scripting/use-powershell-to-work-with-any-ini-file/)**
>
> Summary: Guest Blogger Oliver Lipkau shares two Windows PowerShell functions to simplify reading and writing to INI files.   Microsoft Scripting Guy Ed Wilson here. Today, we have another guest blog post, this one written by Oliver Lipkau....

---

<div class="post-metadata">

### Author: ![progenit0r](https://avatars.discourse-cdn.com/v4/letter/p/a183cd/32.png) [@progenit0r](https://forums.powershell.org/u/progenit0r)
#### Post date: [November 14, 2019, 3:49am UTC](https://forums.powershell.org/t/replace-entire-ini-section/13411/3 "2019-11-14T03:49:19Z")

</div>

> [@](#):
>
> There are many solutions that talk about managing INI files with Powershell, for instance …

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…

---

<div class="post-metadata">

### Author: ![rob-simmers](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/rob-simmers/32/1010_2.png) [@rob-simmers](https://forums.powershell.org/u/rob-simmers)
#### Post date: [November 14, 2019, 9:10am UTC](https://forums.powershell.org/t/replace-entire-ini-section/13411/4 "2019-11-14T09:10:58Z")

</div>

> 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:

> **[Powershell: Everything you wanted to know about hashtables](https://powershellexplained.com/2016-11-06-powershell-hashtable-everything-you-wanted-to-know-about/)**
>
> I want to take a step back and talk about hashtables. I use these all the time now. I was teaching someone about them after our user group meeting last night and I realized I had the same confusion about them at first that he had. Hashtables are...

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
```

---

<div class="post-metadata">

### Author: ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)
#### Post date: [May 16, 2024, 8:31pm UTC](https://forums.powershell.org/t/replace-entire-ini-section/13411/5 "2024-05-16T20:31:09Z")

</div>


