https://github.com/lipkau/PsIni
Work with INI files in PowerShell using hashtables
https://github.com/lipkau/PsIni
Last synced: 4 months ago
JSON representation
Work with INI files in PowerShell using hashtables
- Host: GitHub
- URL: https://github.com/lipkau/PsIni
- Owner: lipkau
- License: mit
- Created: 2013-05-07T13:31:54.000Z (over 12 years ago)
- Default Branch: master
- Last Pushed: 2024-06-17T09:16:27.000Z (over 1 year ago)
- Last Synced: 2024-06-17T10:41:47.593Z (over 1 year ago)
- Language: PowerShell
- Homepage: http://lipkau.github.io/PsIni
- Size: 224 KB
- Stars: 149
- Watchers: 14
- Forks: 49
- Open Issues: 25
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- jimsghstars - lipkau/PsIni - Work with INI files in PowerShell using hashtables (PowerShell)
README
# PSIni
[](https://github.com/lipkau/PSIni/releases/latest)

[](https://www.powershellgallery.com/packages/PSIni)

## Table of Contents
- [PSIni](#psini)
- [Table of Contents](#table-of-contents)
- [Description](#description)
- [Origin](#origin)
- [Installation](#installation)
- [Examples](#examples)
- [Create INI file from hashtable](#create-ini-file-from-hashtable)
- [Read the content of an INI file](#read-the-content-of-an-ini-file)
- [Contributors](#contributors)
## Description
Work with INI files in PowerShell using hashtables.
### Origin
This code was originally a blog post for [Hey Scripting Guy](https://devblogs.microsoft.com/scripting/).
> [Use PowerShell to Work with Any INI File](https://devblogs.microsoft.com/scripting/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](https://www.powershellgallery.com/packages/PSIni)
and can be installed as follows:
```powershell
Install-Module PSIni <# -Scope User #>
```
> **Note:** If you're upgrading from PSIni v3 to v4, please refer to the [migration guide](docs/Migrating-to-v4.md) for details on breaking changes and new features.
---
When using the source (this repository), you can easily get the necessary setup by running
```powershell
. ./tools/setup.ps1
```
_Additional information can be found in [CONTRIBUTING](CONTRIBUTING.md)._
## Examples
### Create INI file from hashtable
Create a hashtable and save it to `./settings.ini`:
```powershell
$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:
> ```Ini
> [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:
```powershell
$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: