PSINI in PowerShell

Poke your INI files with PSINI

Posted by nick on February 04, 2020

Recently I have had to deal with INI files, for anyone who doesn't know what one looks like, its full of key-value pairs

Foo=1
Bar=2

You can have sections [SectionName] too. But quite often, when you are dealing with INI files in a DevOps approach, you want to change values based on something dynamic, be it an IpAddress, URL... something.

To the rescue is the PowerShell module of PSINI. Here is an example of one I did earlier;

Import-Module PsIni

$FileContent = Get-IniContent "c:\file.ini"

$FileContent["tcp_enabled"] = 1
$FileContent["a_value"] = "some text"
$FileContent["http_enabled"] = 1

Out-IniFile -InputObject $FileContent -FilePath "c:\file.ini" -Force

PSINI will load the INI file into memory, and allow you to modify or add additional values. Super easy.