Replace entire ini-section

Welcome Forums General PowerShell Q&A Replace entire ini-section

Viewing 2 reply threads
  • Author
    Posts
    • #188044
      Participant
      Topics: 1
      Replies: 1
      Points: 14
      Rank: Member

      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

    • #188122
      Participant
      Topics: 10
      Replies: 1284
      Points: 1,084
      Helping Hand
      Rank: Community Hero

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

      Managing INI Files with PowerShell

      Use PowerShell to Work with Any INI File

      • #188206
        Participant
        Topics: 1
        Replies: 1
        Points: 14
        Rank: Member

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

    • #188287
      Participant
      Topics: 10
      Replies: 1284
      Points: 1,084
      Helping Hand
      Rank: Community Hero

      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
      
Viewing 2 reply threads
  • You must be logged in to reply to this topic.