Skip to content

lipkau/PSIni

Repository files navigation

GitHub release GitHub Actions Workflow Status PowerShell Gallery License

Table of Contents

Description

Work with INI files in PowerShell using hashtables.

Origin

This code was originally a blog post for Hey Scripting Guy.

Use PowerShell to Work with Any INI File

Over time this project got a lot of enhancements and major face-lifts.

Installation

PSIni is published to the Powershell Gallery and can be installed as follows:

Install-Module PSIni <# -Scope User #>

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.

Examples

Create INI file from hashtable

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
Out-IniFile -InputObject $NewINIContent -FilePath ".\settings.ini"

Results:

[Category1]
Key1=Value1
Key2=Value2

[Category2]
Key1=Value1
Key2=Value2

Read the content of an INI file

Returns the key "Key2" of the section "Category2" from the ./settings.ini file:

$FileContent = Get-IniContent "C:\settings.ini"
$FileContent["Category2"]["Key2"]

Contributors

This project benefited immensely from the contribution of powershell enthusiasts. Thank you ❤️

The Contributors: https://github.com/lipkau/PSIni/graphs/contributors