Work with INI files in PowerShell using hashtables.
This code was originally a blog post for Hey Scripting Guy.
Over time this project got a lot of enhancements and major face-lifts.
PSIni is published to the Powershell Gallery and can be installed as follows:
Install-Module PSIni <# -Scope User #>
Note: If you're upgrading from PSIni v3 to v4, please refer to the migration guide for details on breaking changes and new features.
When using the source (this repository), you can easily get the necessary setup by running
. ./tools/setup.ps1
Additional information can be found in CONTRIBUTING.
Create a hashtable and save it to ./settings.ini
:
$Category1 = @{"Key1"="Value1";"Key2"="Value2"}
$Category2 = @{"Key1"="Value1";"Key2"="Value2"}
$NewINIContent = @{"Category1"=$Category1;"Category2"=$Category2}
Import-Module PSIni
Export-Ini -InputObject $NewINIContent -Path ".\settings.ini"
Results:
[Category1] Key1=Value1 Key2=Value2 [Category2] Key1=Value1 Key2=Value2
Returns the key "Key2" of the section "Category2" from the ./settings.ini
file:
$FileContent = Import-Ini -Path "C:\settings.ini"
$FileContent["Category2"]["Key2"]
This project benefited immensely from the contribution of powershell enthusiasts. Thank you ❤️
The Contributors: https://github.com/lipkau/PSIni/graphs/contributors