Skip to content

lipkau/PSIni

Repository files navigation

PSIni

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

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.

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
Export-Ini -InputObject $NewINIContent -Path ".\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 = Import-Ini -Path "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

About

Work with INI files in PowerShell using hashtables

Topics

Resources

License

Code of conduct

Stars

Watchers

Forks

Sponsor this project

 

Contributors 14