Work with INI files in PowerShell using hashtables
PowerShell
Clone or download
lipkau Merge pull request #39 from lipkau/enhance/WritePrettyIniFile
Added parameter `-Pretty` for writing Ini files
Latest commit 2ce2571 May 25, 2018
Permalink
Failed to load latest commit information.
.vscode Added environment files for VS Code Jan 22, 2018
Examples Sync latest examples Jan 3, 2017
PSIni Added parameter `-Pretty` for writing Ini files May 25, 2018
Tests Added parameter `-Pretty` for writing Ini files May 25, 2018
.gitattributes updated gitattributes Dec 13, 2016
.gitignore Updated gitignore Jan 22, 2018
LICENSE Added LICENSE Oct 14, 2015
PSIni.build.ps1 Reverted breaking changes Jan 22, 2018
README.md Fix a typo and adjust how my name is displayed Jan 3, 2017
appveyor.yml

README.md

PsIni Join the chat

Stories in Ready Stories in Backlog Stories In Progress

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

The individual functions have been published to Microsoft's Script Gallery:

Table of Contents

Examples

Create a Hashtable and save it to C:\settings.ini:

  PS> Import-Module PsIni
  PS> $Category1 = @{"Key1"="Value1";"Key2"="Value2"}
  PS> $Category2 = @{"Key1"="Value1";"Key2"="Value2"}
  PS> $NewINIContent = @{"Category1"=$Category1;"Category2"=$Category2}
  PS> Out-IniFile -InputObject $NewINIContent -FilePath "C:\settings.ini"

Results:

[Category1]
Key1=Value1
Key2=Value2

[Category2]
Key1=Value1
Key2=Value2

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

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

Authors/Contributors

Author

Contributor

Documentation

Wiki Documentation